LeetCode 135 Candy - Solution

The pattern

Two passes: left-to-right, then right-to-left.

Left-to-right: if rating[i] > rating[i-1], give candy[i] = candy[i-1] + 1.

Right-to-left: if rating[i] > rating[i+1], candy[i] must be at least candy[i+1] + 1.

Take the max of both passes for each child. This satisfies both neighbor constraints.