Leetcode 135. Candy
Given a line of children with integer ratings, assign each at least one candy so any child with a higher rating than a neighbor gets more candies, and compute the minimum total required; the core challenge is balancing local increases/decreases across the array (typically handled by scanning increasing/decreasing runs or a two-pass greedy) in linear time.
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
Late August, 2026
You have n children standing in a line, and each child has a rating value given in an array called ratings. You need to distribute candies to these children following these rules: Every child can receive zero no of candies If a child has a higher rating than their neighbor (the child directly to their left or right), they must receive more candies than that neighbor and child should have different no of candies then their neighbour. Your task is to find the minimum total number of candies needed to satisfy requirements.
Early December, 2025
Late October, 2025
Hello Interview Premium
Your account is free and you can post anonymously if you choose.