Back to DSA

Candy

hard
Acceptance: 36%
GreedyArrays

Children stand in a line, each with a rating score. Distribute candies so that every child gets at least one and any child with a higher rating than an immediate neighbor receives more candies than that neighbor. Compute the minimum total candies required.

Examples

Example 1:
Input:ratings = [1,3,2]
Output:4
Example 2:
Input:ratings = [1,2,2]
Output:4

Hints

00:00
1234567