// 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
13 min◆◆IntermediateAmazonMeta
02Cyclic Sort
Cyclic sort: the O(n) time, O(1) space pattern for arrays holding values 1..n — swap each value to its home index, then scan for missing numbers and duplicates.
#arrays#sorting#patterns
11 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
11 min