You are given an array ratings, where each element represents a child’s rating. You need to distribute candies to these children while meeting certain rules.
Each child must get at least 1 candy. Children with higher ratings must receive more candies than their neighbors.
The problem can be efficiently solved using a two-pass greedy approach.
The time complexity of the solution is O(n), where n is the number of children.