Candy
Signals to notice
Brute force first
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.
The key insight
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.
What must stay true
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.
Easy way to go wrong
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.