Sunday, July 1, 2018

Being interviewee: Regular expression match

July 1, 2018

Introduction


It was my 10:00 PM mock interview on June 30, 2018. It is my favorite algorithm called regular expression matching, and it is hard level. I have not written any new algorithm in the whole week. The peer did such great job to help me go over the tough thinking process to write code in 40 minutes, and a few debugging to pass 4 out of 6 test cases. After the mock interview, the peer shared with me her Google onsite interview experience and Linkedin onsite experience, so generous sharing. I also learned the lesson to keep practicing.

Dynamic programming one more practice


Here is the code I wrote in mock interview 40 minutes.

I mixed the text string and pattern string. On line 41,

Line 41: else if(currentP == '*' && row >= 2 && text[row - 2] != '*')

The above statement row variable checking should be col >= 2 && pattern[col -2] != '*'

Here are a list of things to slow me down in mock interview:

1. Line 25, write down base case for dynamic programming table first row, when the text string is empty, "b*", ".*", "a*b*" should match empty string.

   The expression can be simplified as well.

2. Line 44 missing pattern[col - 2] == '.' for one or more than one case.

Here is the C# code I fixed the bug after the mock interview.

No comments:

Post a Comment