Friday, November 3, 2017

Leetcode 37: Sudoku solver

Nov. 2, 2017

Introduction


It is the time again to write a Sudoku solver. Here is my C# practice, the peer told me that I do not need to run the code using web browser compiler.

The mock interview was supposed to end in one hour to 11:00 PM, but it actually ended at 11:50 PM. I spent more time to chat with the peer until the session terminated due to timeout.

After that, I started to run the code, first I fixed the grammar error line 62. The Split function of string will have an array of string, not an array of char. The line 62 has compile error. It is the easy and quick fix. But I came cross the index out of range run time error. This one I could not pinpoint the error.

I was troubled and tried to set up test case until 1:00 AM, and then I called it a day. I did not do whiteboard testing, instead I tried to guess what is possible places to go wrong for index-out-of range error. With whiteboard testing, it should be a quick fix. But without it, I wasted almost one hour but I still could not find the issue until 1:00 AM.

Whiteboard testing


The whiteboard testing is to use a test case and go over the code line by line, write down the value for each variable, and run the code virtually with results.

If I do whiteboard testing, I should have found the bug on line 91. Here is line 91 with the bug:

for(int row = startRow; row < row + 3; row++)

actually when I run the whiteboard testing, startRow = 0, then row is from 0 to 2. The statement should be written in the following:

for(int row = startRow; row < startRow + 3; row++)


Nothing beats whiteboard testing 


In terms of bug fixing, nothing beats whiteboard testing. Go over a simple test case, go over each line of code, put the result next to the code.

Actionable Item


C# code is updated and it passes all test cases after mock interview. The C# code is here

Review sudoku algorithm on code review website, and I studied the question:

Solving Sudoku using backtracking

Plan to write C# code based on the above code review. I feel that there are a few things I can apply to my mock practice code. 


Plan to write a blog to review algorithm of longest common subsequence written in Chinese. The link is here.

No comments:

Post a Comment