Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.

Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).

If yes, their candies are equal? if ratings are [1, 3, 3, 4], candies can be 1, 2, 2, 3 ? or 1, 2, 1, 2?

Neighbour who have same rating, could get different amount of candy.

So, for your test case [1, 3, 3, 4], the best solution should be 1, 2, 1, 2.

[1, 3, 3, 4]

1, 2, 1, 2

This requirement should be given. Very easily assume that equal ratings have equal candies, otherwise children will fight...

This wrong submission will answer your question. Input: [1,2,2] Output: 5 Expected: 4

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.