Sunday, February 4, 2018

Find smallest substring containing all keys

Feb. 4, 2018

Introduction


It is the algorithm I have to write for my 10:30 PM mock interview. The peer was very helpful and I had 30 minutes to complete the analysis and code, I did fix the grammar error in last minute and pass all test cases.

I can tell the difference. Since I understand the process of sliding window containing substring, how the left pointer can slide through if the substring contains all keys. I had one practice in January and then I got a few advice to optimize the algorithm. This time I could write the algorithm much quickly.

The peer advised me to speed up coding if I can.

Code review


The C# code is here. The peer advised to add extra variable to store the start position of substring, I added variable on line 21 called startIndex.




No comments:

Post a Comment