Showing posts with label my second coach USA style. Show all posts
Showing posts with label my second coach USA style. Show all posts

Tuesday, May 29, 2018

Being an interviewee : Insert intervals

May 29, 2018

Introduction


It is the interval algorithm but it is not easy for me to come out elegant idea to write simple code. I had some ideas, but before I came out the idea, I already wrote the code. The interviewer told me stop, and told me that I should make it simple.


Ideas 


Here is the transcript of the mock interview.

Hints pouring down 


I like the interviewer. He just quickly coached me through mock interview. I like to exaggerate how he did. He poured down hints one by one. I really like young talent Chinese graduate student, how hard he works, and he is willing to coach me. He did 3 times mock interviews with me, and this is the third time. I like his good collabration skills. I do believe that the future will be better with those young gradautes.

A few hints are given by the interviewer and the interviewer helped me to get the optimal solution and also very clean implementation:

1. About inserted interval, it can be replaced by current visited element
2. inserted interval can be replaced by the merge interval of two overlapped intervals.
3. Write simple code, I wrote the code to check next interval and logic is too complicated for the interviewer to follow. It may work, but the interviewer told me that it is better to discuss with the interviewer first.
4. The interviewer told me that it is better to ask hints, instead working on complicated solution. I do not totally agree on this.
5. If I am too busy to work on the code by myself, the interviewer may not have chance to work with me.

Follow up 


I wrote C# code and also I found a bug. Actually if I check my coding style and I should find the bug. Those two lines of code with variables insertedStart, insertedEnd, the scope should stay inside for loop. Now they are moved to line 60 and line 61.


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.