Pattern Variations
See how one core pattern survives even when the rules and constraints change.
0 of 4 problems solved
Pattern Variations
See how one core pattern survives even when the rules and constraints change.
- •What stayed the same from the base problem?
- •What changed in the constraints or allowed operations?
- •Can I keep the pattern and only change the invariant?
Pattern Variations teach you that the same engine can power many different problems. One rule changes, one constraint shifts, one detail becomes stricter, and suddenly the problem looks new. But the underlying pattern often stays the same. Learning to see that is how you stop memorizing isolated solutions and start thinking like an engineer.
A variation usually changes the details of the invariant, not the entire pattern.
- 1Identify the base problem you already know.
- 2Ask what exactly changed: sorted input, duplicates, fixed window, graph direction, and so on.
- 3Keep the same core pattern if it still fits.
- 4Only modify the part of the logic that the new constraint touches.
Rewriting from scratch every time hides the connection between problems that are actually close cousins.
Squares of a Sorted Array
Two pointers from both ends. The largest square is always at one extreme. Fill the result array from right to left.
Meeting Rooms III
Two priority queues: one for free rooms sorted by index, one for active meetings sorted by end time. Simulate each meeting and assign the earliest-freed available room.