Back to DSA
Candy
hardChildren 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:
4Hints
1234567