Sunday, December 17, 2017

Leetcode 10: regular expression matching

Dec. 17, 2017

Introduction


It is the best mock interview so far I have. I met a very senior developer working in Seattle area, and then I have to work on the algorithm called regular expression matching.

It is the challenging algorithm and very classical. I was told to work on dynamic programming and the peer likes to help me to work on the analysis and coding. But my argument is if I write a recursive with memo correctly then it should be easily applied to dynamic programming.

Code review


Here is the code I wrote in mock interview. The peer gave me instant feedback right away, and also wrote comment right away while I write first few lines of code.

Line 44 - 53, the code failed 6 test cases, only passed two test cases. I was told by the peer that I missed the test case like "" match pattern string "a*b*.*".

Also line 51, if the pattern string has only one char, it should return checking (char == '.'). The peer explained to me by adding the comment, using test case to help me understand the bug.

I fixed the variable issue on line 61, patternIndex variable should be used instead of using textIndex.

No comments:

Post a Comment