You are viewing a single comment's thread. Return to all comments →
I did this and it works perfectly. I'm kinda new, but the solution is dynamic programming right?
Forward-pass for all up-trends: Subproblem = test arr[i] > arr[i-1], candy[i] = candy[i-1] or candy[i]
arr[i] > arr[i-1]
candy[i] = candy[i-1] or candy[i]
Backwards-pass for all up-trends: Subproblem = test (candy[i] < candy[i+1]) and (arr[i] > arr[i+1]), candy[i] = candy[i+1] + 1
(candy[i] < candy[i+1]) and (arr[i] > arr[i+1])
candy[i] = candy[i+1] + 1
Just need to get the array referencing correct and you're good!
Candies
You are viewing a single comment's thread. Return to all comments →
I did this and it works perfectly. I'm kinda new, but the solution is dynamic programming right?
Forward-pass for all up-trends: Subproblem = test
arr[i] > arr[i-1]
,candy[i] = candy[i-1] or candy[i]
Backwards-pass for all up-trends: Subproblem = test
(candy[i] < candy[i+1]) and (arr[i] > arr[i+1])
,candy[i] = candy[i+1] + 1
Just need to get the array referencing correct and you're good!