The Question
CodingCandy Distribution Minimization
There are n children standing in a line, each assigned a specific rating value. You need to distribute candies to these children under two conditions:
1. Every child must receive at least one candy.
2. Children with a higher rating than their immediate neighbors (left or right) must receive more candies than those neighbors.
Write a function to calculate the minimum total number of candies required to satisfy these conditions.
Constraints:
- 1 <= n <= 2 10^4
- 0 <= ratings[i] <= 2 10^4
Java
Greedy