Wednesday, March 14, 2018

Sudoku solver

March 14, 2018


Introduction


It is my most favorite algorithm in the world. I could not believe that I practiced today with an engineer in Oregon and also I did learn a few things through mock interview. I took extra 30 minutes to discuss with the peer about algorithm practice and exchange ideas. The peer recommended me to practice on codefights.com, consider the purchase of interviewcake.com algorithms with the answers.

I remembered that in 2015 I did study over 5 solution on Sudoku solver algorithm, I spent over 40 hours to practice the algorithm. At that time, I thought that I was the expert on the algorithm. It was so naive and here is the blog link for those practices.

Code practice


I spent less than 10 minutes to analyze the algorithm, and then the peer asked me if I can improve the efficiency to get available numbers to replace '.' char. So I plan to use a hashset to store available numbers.

After I finished the code, I ran the test cases, I only passed one of test cases. So I found out that the hashset should be digits from 1 to 9 excluding those number showing in the same row or column or 3 x 3 small matrix. I just naively got those numbers and put into the hashset instead.

Here is the code. It took me exactly 30 minutes to pass all test cases. I spent around 5 minutes to fix all bugs.


No comments:

Post a Comment