Wednesday, May 23, 2018

Being an interviewee: Leetcode 42: Trapping rain water

May 23, 2018

Introduction


I asked my friend to give me a mock interview and he offered me to practice mock interview Tuesday and Thursday and Friday for 45 minutes each time. He did very good job to ask me to work on Leetcode 42: Trapping rain water. He also gave me some good advice, but he gave out the major hint too quick so that I did not have to come out the solution by myself.

I was nervous and talked about brute force solution, and then talked about descending stack. I made a mistake to try to relate to the algorithm I practiced recently. This is a bad behavior, the interviewer had discussion with me at the end of mock interview. I should get rid of this non reasoning thinking, I am supposed to work on the algorithm I have never seen before. So I have to practice my approach based on the facts, test cases, intuition etc.

The solution is nothing to do with descending stack, but the interviewer just gave away the major hint. He told me to scan two times, one is from left to right, the second one is to scan right to left.

Mock interview 


Here is the transcript of the mock interview.

Follow up


After mock interview, I wrote a C# solution. Here is the link.

Ask help from my coach in Tsinghua university


I sent an email to my coach to ask help on May 25 12:20 AM:

I am glad to find you as my coach. Here is the algorithm I mocked interview Tuesday with Mr. Yang. I did not do very well on analysis, take a look if you have a few minutes.

Here is the blog link.

I have to call it a day. Talk to you later.

May 25, 2018
8:20 AM
The coach told me that I did not have time to develop the solution using descending stack. Actually the rain water is filled up for each time range incrementally. He explained the algorithm to me based on given test case, I understand the algorithm right away.

Basically there are multiple ways to solve the algorithm, my interviewer only knows one way to solve it.

I will write C# solution based on descending stack later.

No comments:

Post a Comment