#arrays
9 articles
Arrays and How Memory Really Works
Go under the hood of the most fundamental data structure — contiguous bytes, O(1) index addressing, cache lines, and why a sequential scan beats a random walk every time.
Strings
Strings are immutable arrays hiding an O(n²) concatenation trap. Learn the sliding window, two-pointer, and hashing patterns that crack string interviews.
Arrays
The data structure everything else is built on. Why arr[i] is instant, why inserting in the middle hurts, and the handful of patterns that turn arrays into interview wins.
Prefix Sums
Precompute running totals so any range sum becomes one subtraction. The prefix sum technique turns O(n) per query into O(1) — and the hashmap combo unlocks a whole class of subarray counting problems.
Monotonic Stacks
Master the monotonic stack — the O(n) pop-while trick behind next greater element, Daily Temperatures, Largest Rectangle, and Trapping Rain Water.
The Merge Intervals Pattern
Master the merge intervals pattern: sort by start, sweep once, and crack meeting rooms, calendar conflicts, and range overlap problems in O(n log n).
Cyclic 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.
The 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.
The Sliding Window Pattern
Learn the sliding window technique: solve longest/shortest subarray and substring problems in O(n) with the expand-right, shrink-left template.