Tuesday, February 27, 2018

Find smallest substring containing unique keys


Feb. 27, 2018


Introduction


I had two mock interviews as an interviewer and the algorithm is find smallest substring containing all keys. I had chance to observe how top university graduate learned the algorithm from the scratch. I know that it is hard level algorithm, even though one of peers is top graduate and very well educated, but understanding the idea and putting them into the code are two different talent. I just learned that the peer wrote a portion of the algorithm to use a hashset to check sliding window containing all keys or not.

The code was so buggy and even I could not handle the code very well. I missed the bug even after I reviewed the code. It took us more than 10 minutes to work on the code together.

Through the process, I definitely could tell that the peer was working very hard. The peer communicated very well.But coding takes some practice. It cannot be shortened without failure, mistakes, and all kinds of issues in-between.


Code review


Since I reviewed the code, I should claim part of the ownership of the code. I should copy the code and remind myself later on, be more careful when I review the code.

The mistake is
unorder_set<char> map
...
map.insert(arr[left])
map.insert(arr[right])

The char should be str[left], str[right] instead. I made the same mistake before to mix two variable names, from that on, I always go ahead in the beginning to change the variable names in the meaningful way.

No comments:

Post a Comment