I was trying to "brute force" this with a ton of if/else statements... Just your explanation of how to approach the problem alone and I could solve it! Thank you and great job!
On what grounds we decide that we need to travel in both the directions? i.e. forward as well as backwards? Because for this scenario of {5,4,3,2,1} if we consider then only 9 candies needs to be distributed instead of 15. I am not getting this part! 5,4,3,2,1 (Kids) 1,1,1,1,1 (Initial value of candies) 2,1, (1st iteration) 2,2,1 2,2,2,1, 2,2,2,2,1
Hi chirag, in interview prepration kit it was in dynamic section.. I have written same topic here but if you go through the problem you find its not a dynamic one ... You can solve with dynamic approach and feel free to post your answer so that other can get benefitted too.