Sunday, February 25, 2018

Find first missing number

Feb. 25, 2018

Introduction


It is part of my training idea, practice until you cannot get it wrong. I had a mock interview this morning at 10:00 AM. I did write down the idea to do in place swap to find the first missing number. And then I wrote code with a few bugs, I failed a few test cases, and then I fixed the bugs on line 15 and also line 16.

Practice until you cannot get it wrong


One thing I like to train myself through mock interview is to pay attention to small detail. The peer asked me to work on the optimal solution using in place, and then I came out the idea but I did say something to change the value to negative one if the value is bigger than the array size. And the code I wrote was not correct, I ran into index-out-of-range error and failed a few test cases. I fixed the bugs of course very quickly.

Line 18 swap function should be called only after the index is in the array's range.

Here is C# code.

The mistakes I made in my first writing just reminds me that I have to train myself hard than before.

No comments:

Post a Comment