Candy

There are n children standing in a line, each with a rating value in the integer array ratings. Candies are distributed to them with the following conditions: each child receives at least one candy, and children with higher ratings receive more candies than their neighbors. The task is to find the minimum number of candies required to satisfy these conditions.

Constraints

  • n == ratings.length
  • 1 <= n <= 2 * 10^4
  • 0 <= ratings[i] <= 2 * 10^4
Saving… · 3 lines
class Solution:
def distributeCandies(self, ratings):

Console

Click Run to execute sample tests.