// TOPIC
#patterns
3 articles
◆◆IntermediateAmazonGoogle
01The Top-K Elements Pattern
How a heap of size k gives you the k largest (or smallest, or most frequent) items in O(n log k) — and why a min-heap is the counterintuitive tool for finding the biggest things.
#heaps#priority-queues#hash-maps
11 min◆◆IntermediateAmazonMeta
02Cyclic Sort
The O(n) time, O(1) space trick for arrays that hold numbers in a known range 1..n: place each value at its natural index, then scan once for anything out of place. Missing numbers, duplicates, and corrupt pairs fall out as a natural consequence.
#arrays#sorting#patterns
10 min◆◆IntermediateAmazonMeta
03The Two Pointers Pattern
A sorted array and an O(n²) instinct — two indices, moving in tandem, collapse it to O(n). Here is the pattern, the tell that signals it, and every problem variant you will see.
#two-pointers#arrays#sorting
10 min