Coding patternsArrays and strings
Coding patterns for arrays and strings
Hash maps and prefix sums, two pointers, sliding windows, binary search and stacks turn an O(n²) scan into one pass. Then linked lists, intervals, matrices, bits and greedy choices.
10 topics.
- 01FoundationReadHashing and prefix sumsTrade memory for time: remember what you have seen so you never scan for it again.
- 02FoundationReadTwo pointersTwo indexes that only move forward turn a nested loop over pairs into one pass.
- 03Mid-levelReadSliding windowGrow the right edge, shrink the left, and keep the window valid the whole way.
- 04Mid-levelReadBinary searchHalve the search space each step, on sorted arrays and on the answer itself.
- 05Mid-levelReadStacks and monotonic stacksMatching brackets, undoing work, and finding the next greater element in one pass.
- 06FoundationReadLinked listsA dummy head, fast and slow pointers, and flipping arrows in place without losing the rest.
- 07Mid-levelReadIntervalsSort by start, then merge, count overlaps or sweep the line from left to right.
- 08FoundationReadMatricesWalk a grid by rows, rings and neighbors, and mark cells in place instead of copying.
- 09Mid-levelReadBit manipulationMasks, shifts, x & (x - 1) and XOR: answers in O(1) memory from the bits themselves.
- 10Mid-levelReadGreedyMake the best local choice, and prove with an exchange argument that it is never wrong.
More in Coding patterns
The designbeyondcode digest, every Saturday
New deep dives, interview tips and site news in one short email. Free. Leave with one click.
We never sell or share your email. We only use it to send this newsletter.