Practice Candy
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Give candies to children standing in the order of ratings. Every child must receive at least one candy. Whenever two adjacent children have different ratings, the child with the higher rating must receive more candies. Return the smallest possible total; equal ratings do not impose an equal-candy requirement.
Source: Candy on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
ratings = [1,0,2]
Output
5
# Example 2
Input
ratings = [1,2,2]
Output
4
Constraints
n == ratings.length
1 <= n <= 5 * 10^4
0 <= ratings[i] <= 5 * 10^4
Related LeetCode Problems
Practice more problems similar to Candy.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.