LeetCode HARD 135 Candy Summary
Generated by Codex with GPT-5
Quick facts
- Difficulty:
HARD - Problem: Candy
- Main tags:
Array,Greedy
What the problem is really asking
There are children standing in a line. Each child has a rating, and the goal is to give out the fewest total candies while obeying two rules:
- every child gets at least one candy
- any child with a higher rating than an adjacent child must get more candies than that neighbor
The important detail is that the comparison is only between neighbors. A child does not need more candy than every lower-rated child, only more than the children immediately to the left and right when their rating is higher.
Continue ...