Children stand in a line with ratings. Each child gets at least 1 candy. Children with higher rating than neighbors must get more candies than those neighbors. Minimize total candies.
Example: ratings = [1,0,2]. Child 0 has rating 1, child 1 has rating 0, child 2 has rating 2. Candies: [2,1,2]. Total: 5.
This needs two passes. One pass cannot satisfy both left and right neighbor constraints simultaneously.