Children stand in a line with ratings ratings[i]. Every child gets at least one candy, and a child with a higher rating than a neighbour must get more candies than that neighbour. Return the fewest candies needed.
For [1, 0, 2] the answer is 5 (candies 2, 1, 2).
Example 1
Input:
candy([1, 0, 2])
Output:
5
Example 2
Input:
candy([1, 2, 2])
Output:
4
0 <= len(ratings) <= 2000000 <= ratings[i] <= 10**9No results yet
Run your code to check it against the examples, or submit to run every test.