Candy
Recognize the pattern
Brute force idea
A straightforward first read of Candy is this: Iteratively adjust candies until all constraints are met — worst case. May require multiple passes. That instinct is useful because it follows the prompt literally, but it usually keeps revisiting work the problem is begging you to organize.
Better approach
The real unlock in Candy comes when you notice this: Two passes: left-to-right ensures each child has more than their left neighbor if their rating is higher. Right-to-left ensures the same for right neighbors. Take the max at each position. Instead of recomputing the world every time, you preserve just enough context to let the next decision become obvious.
Key invariant
The compass for Candy is this: The left-to-right pass satisfies all left-neighbor constraints. The right-to-left pass satisfies all right-neighbor constraints. Taking the max of both ensures both are satisfied simultaneously. As long as that statement keeps holding, you can trust the steps built on top of it.
Watch out for
A common way to get lost in Candy is this: Doing only one pass — a single pass can't satisfy both directions simultaneously. The two-pass approach handles increasing and decreasing sequences independently. Most mistakes here are not about syntax; they come from losing track of what your state, pointer, or structure is supposed to mean.