Introduction
It is 4:00 PM mock interview. I had to work on the dynamic programming algorithm. In the analysis, I analyze the right to left dynamic programming method, and I need to work on two multiplications each iteration. But I wrote down a line on line 58 which is wrong:
product[i] = product[i] * arr[i + 1]
Code practice
The peer gave me the hint, and then I wrote down line 63 and line 64:
line 63: rightProduct = 1,
line 64: rightProduct *= arr[i + 1]
I like to figure out what I should do to come out the correct analysis in the first time. If I am a teacher and I teach algorithm every day, I may come out a few ideas to help myself to follow certain steps to write correctly on whiteboard.
Right now I only emphasis two multiplications in right to left iteration using dynamic programming methods. But I still could not connect dots in between. Do not worry, next time I will make it perfect.
Here is my code practice in C#.
No comments:
Post a Comment