largest product in a grid
I do not like such kind of problem, Basically, we need to brute force it. However, your code should not exceed 0.5 second. Otherwise, you need to check your code.
Update:
I read my code a few days ago, I failed to understand what was going on in my code. It was really messy! I found that I used meaningless variable names like i, j, k and use some magic numbers like 17 and 37, etc. The logic under the code is not lucid at all.
I started trying to modify the old code, and begin to use meaningful names like row and col. After a few minutes, I found that some of my code can be reorganized in a simpler way. I did it and then found a better way to handle the main diagonal and off-diagonal. The code is cleaner now and very easy to understand.
I should be more serious on all coding problems even if I got the correct answer and the problem is believed to be really simple!
No comments:
Post a Comment