There are children in a line, each with a rating. Give each child at least candy. Children with higher ratings than neighbors must get more candy. Minimize total candies.
This is LeetCode . One pass isn't enough because you don't know how many candies the right neighbor will need. Two passes solve this.