Feb. 21, 2022
Introduction
I started to practice mock interview on interviewing.io since I have 27 peer mock interviews. Today I was asked to work on 42. Trapping Rain Water
My feedback
The interviewer asked to calculate the amount of trapping water given an array of integer. I did come out linear solution to calculate prefix and suffix, and then he asked me to calculate the water using given test case by hand. I did the calculation first, and then wrote the code, and tested the code to make it work. The interviewer asked me to come out space optimal solution using O(1) instead of O(N), he came out two pointer solution, and then explained it to me. After discussion, I tried to give counter example, and then I noticed that it is not necessary to find rightmost maximum if left maximum is smaller than current right one. I should have analyzed carefully for the constraint. The discussion was very relax, and interviewer gave me a lot of encouragement. Great thanks.
My algorithm
Work on O(N) time complexity, O(1) space | Two pointers technique
No comments:
Post a Comment