Sunday, February 25, 2018

Find minimum substring containing all unique keys

Feb. 25, 2018

Introduction


It took me 25 minutes to analyze the algorithm and also write C# code. I used exactly 30 minutes to complete the task.

Code review


Here is the C# code passing all test cases.



Comparison to the practice 5 month ago


The code I wrote is much more simple compared to the one I wrote more than 5 month ago, I can look up the code through the question I asked on stackexchange.com.

The while loop to handle left pointer is much simple using one variable to count unique keys in sliding window. The loop invariant is clear and short compared to the one asked in the code review. The loop invariant in the while loop in the code review is giant expression and should be shortened.

No comments:

Post a Comment