6d ago · 19 min read · TLDR: Place one pointer at the start and one at the end of a sorted array. Move them toward each other based on a comparison condition. Every classic pair/partition problem that naively runs in O(n²)
Join discussion
6d ago · 20 min read · TLDR: Instead of recomputing a subarray aggregate from scratch on every shift, maintain it incrementally — add the incoming element, remove the outgoing element. For a fixed window this costs O(1) per
Join discussion
6d ago · 21 min read · TLDR: Move a slow pointer one step and a fast pointer two steps through a linked structure. If they ever meet, a cycle exists. Then reset one pointer to the head and advance both one step at a time —
Join discussion
6d ago · 16 min read · TLDR: Sort intervals by start time, then sweep left-to-right and merge any interval whose start ≤ the current running end. O(n log n) time, O(n) space. One pattern — three interview problems solved.
Join discussion
6d ago · 17 min read · TLDR: Reversing a linked list in O(1) space requires three pointers — prev, curr, and next. Each step: save next, flip curr.next to point backward, advance both prev and curr. Learn this once and you unlock four reversal variants that appear constant...
Join discussion6d ago · 16 min read · TLDR: DFS explores a graph by diving as deep as possible along each path before backtracking, using a call stack (recursion) or an explicit stack. It is the go-to algorithm for cycle detection, path finding, topological sort, and connected components...
Join discussion6d ago · 16 min read · TLDR: If an array holds n numbers in range [1, n], each number belongs at index num - 1. Cyclic sort places every element at its correct index in O(n) time using O(1) space — then a single scan reveals every missing and duplicate number. Five intervi...
Join discussion6d ago · 18 min read · TLDR: Binary search has five patterns beyond the classic "find the target": leftmost position, rightmost position, rotated array search, minimum in rotated array, and 2D matrix search. The root of every off-by-one bug is a mismatched loop condition a...
Join discussion6d ago · 17 min read · TLDR: BFS explores a graph level by level using a FIFO queue, guaranteeing the shortest path in unweighted graphs. Recognize BFS problems by keywords: "shortest path," "minimum steps," or "level order." Time: O(V + E). Space: O(V). Mark nodes visited...
Join discussion