Wednesday, September 20, 2017

Leetcode 57: Insert Interval

Sept. 20, 2017

Introduction



It is definitely a good learning process to help the peer work out the optimal solution to solve intervals. I had a mock interview 10:00 PM, and I had to spend over 30 minutes to help the peer to work on an interval algorithm. The difficult part is to explain the idea to use linear algorithm to solve the problem. Also, I gave the hint to show how to get the overlap quickly using Math.Max of beginning of two intervals and Math.Min of ending of two intervals, and then I gave the hint to move to next interval if the ending value is the smaller one.

I gave out the code review about a double for loop, and explained to the peer, in order to get linear time complexity, the while loop should be used instead of using double for loop.

So after the mocking interview, I like to review interval algorithms in Leetcode.

Plan to work on hard level algorithm called Insert Interval. The link is here.

No comments:

Post a Comment