Introduction
It is my algorithm called Find the duplicate in two cases, both sorted arrays has the size close to each other, or one is much larger than the other one. I had the mock interview, after the peer solved the Sudoku solver, I solved my algorithm next.
What I did is great, I gave the analysis of the algorithm for those two cases, I wrote down the analysis from line 95 to line 110. But I came cross a bug of out of memory for my solution to use two pointers. Usually it is show time for me to solve the problem in one try, less than one minute.
Based on my past experience, I was complained one time by a Ph.D. student of University of Florida who prepared for Google phone screen, he told me that I should focus on the error message, and then think about the possible places for the bug. Do not do wild guess trouble shooting.
Related to out of memory bug, it is not index-out-of-range, what is possible reason?
Actually it is a dead loop, but I turned to my first thought. I wrote brute force solution to replace duplicate.ToArray() on line 40 instead at the first try. I did not use my analysis in this trouble shooting.
After more than 250 mock interviews, I found another issue today for my practice.
After a few minutes, the peer told me that I missed two lines of code if the duplicate item is found. I need to advance two pointers.
Code review
Here is my C# code and the code passes all test cases.
No comments:
Post a Comment