Thursday, April 26, 2018

Being interviewee: Matrix spiral copy

April 26, 2018

Introduction


It is my most favorite algorithm called Matrix spiral copy. I told the peer that I like to write a solution to automate direction change but use extra array to store visited information.

I was nervous since last time I wrote the solution was months ago. I am kind of memorizing the solution. What I did is to use wisdom learned through 300 mock interview experience, I tell the peer that I like to visit first row 5 elements 1, 2, 3, 4, 5. How will I do it?

Mock interview


I had discussion with the peer and the peer questioned me the problem I had to visit first element 1 twice. I missed the reset of row and column variables from line 44 and line 45, and also line 42 to set visited array on nextRow, nextCol true.

How come I discussed the solution with the peer with 2 most important task missing? I told the peer that my code will pass all test cases.

I failed last test case and then I noticed that I need to add line 44 and line 45. I need to reset row and col variables. And then I still failed another test case, I noticed that I need to set visited array; and then I still failed the test case, I noticed that I need to set [nextRow, nextCol] instead of [row, col].

What a mock interview!

I need to structure my mock interview better, guard with the whiteboard testing.

Here is my C# code.

Good thing is that I spent less than 20 minutes to write the code with the analysis. The bugs is very easy to fix and code is minimum. It took me less than five minutes to fix all the bugs.

The challenge part is to write correct code and do whiteboard testing by myself.


No comments:

Post a Comment