Workspace Monotonic Stack
0d
Problem-solving patterns

Monotonic Stack

Keep unresolved indices in monotone value order.

Recognition signal

Find the next larger, smaller, or strictly warmer item.

Method

Pop and resolve candidates dominated by the current item, then push its index.

Worked example

For temperatures [20, 18, 23], day 2 resolves both earlier days.

Common mistake

Strict and non-strict comparison treat equal values differently.