We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
This is a good observation. I spent a lot of time solving this question (I am a beginner). I personally don't approach a problem in the view of solving it by DP, but spend some time just thinking about the solution. Also the presence of recurrence relations gives an indication of solving it by recursion and optimizing the code by using DP.
In this case I would suggest you to actually look at the problem in a mathematical way. Given the hint that this problem is categorized under DP, try to find a recurrence solution. And then write the code. I found a conceptually more obvious solution which is also O(N). I hope even you get it.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Bricks Game
You are viewing a single comment's thread. Return to all comments →
This is a good observation. I spent a lot of time solving this question (I am a beginner). I personally don't approach a problem in the view of solving it by DP, but spend some time just thinking about the solution. Also the presence of recurrence relations gives an indication of solving it by recursion and optimizing the code by using DP.
In this case I would suggest you to actually look at the problem in a mathematical way. Given the hint that this problem is categorized under DP, try to find a recurrence solution. And then write the code. I found a conceptually more obvious solution which is also O(N). I hope even you get it.