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.

My solution is simmilar to yours. Logic behind this is that if you make a graph between marking and index of child then local minima will always have 1(min) candy. Then next on both sides of local minima will have 1(min) + 1 candy and so on. This approach can be easily implemented by the method you mentioned above.

I don't quite understand this line in the second half of your code:
(markings[i] > markings[i+1] && (markings[i+1] + 1) > markings[i])

this logically translates to "markings[i] > markings[i+1] && markings[i] <= markings[i+1]", which will always evaluate to false...and thus candies[i] will be assigned to candies[i] every time...so how exactly will this still work as intended?

## Candies

You are viewing a single comment's thread. Return to all comments →

My solution is simmilar to yours. Logic behind this is that if you make a graph between marking and index of child then local minima will always have 1(min) candy. Then next on both sides of local minima will have 1(min) + 1 candy and so on. This approach can be easily implemented by the method you mentioned above.

but what about when the adjacent enteries are equal??

I don't quite understand this line in the second half of your code: (markings[i] > markings[i+1] && (markings[i+1] + 1) > markings[i])

this logically translates to "markings[i] > markings[i+1] && markings[i] <= markings[i+1]", which will always evaluate to false...and thus candies[i] will be assigned to candies[i] every time...so how exactly will this still work as intended?