Notes
Coding questions I have worked through, with the pattern to remember.
SHOWING 6 OF 12 NOTES
Sort
- Newest first
- Oldest first
- Problem #, lowest first
- Problem #, highest first
- Title A–Z
- Title Z–A
- Easiest first
- Hardest first
- EasyOct 14, 2026
- two pointers
- string
Valid Palindrome"compare the start with the end" (palindromes, reversing in place, pair sums on a sorted array) → two pointers moving inward, O(1) space. When some elements must be ignored, skip them with inner while loops that also check left < right. - MediumOct 14, 2026
- array
- hash set
- union find
Longest Consecutive Sequence"longest run of consecutive values in O(n), original order doesn't matter" → put everything in a hash set and only start counting at run starts (x - 1 not in set). A nested while is still O(n) total when each element is walked at most once: argue it by amortization, not by counting loop depth. - MediumOct 13, 2026
- array
- hash set
- matrix
Valid Sudoku"no duplicates within each group" → a seen set per group, filled in a single pass. For grids, map each cell straight to its groups: row r, column c, box (r // 3) 3 + c // 3 (in general, block (r // h, c // w)). Computing the group index from the cell is simpler than looping over each group separately. - MediumOct 13, 2026
- array
- sorting
- two pointers
- and sweep line, heap
Meeting Rooms II"how many things are active at the same time" / "minimum resources so nothing clashes" → peak overlap. Sort the start times and the end times separately and sweep with two pointers (or sort ±1 events). Pairing doesn't matter, only the order of events. Decide the tie rule explicitly: end-before-start when touching intervals don't overlap. - MediumOct 13, 2026
- array
- dynamic programming
- prefix sum
Taking Maximum Energy From the Mystic Dungeon"the path from i is fixed and continues from a later index" → DP from the right: dp[i] = val[i] + dp[next(i)], answer = best dp[i]. With a fixed jump k the board splits into k independent chains, and the DP is just a suffix sum on each chain. Mandatory landings mean you can only trim the start, never the middle. - MediumOct 09, 2026
- array
- prefix sum
- prefix product
Product of Array Except Self"combine everything except index i" (or "everything left of i" / "everything right of i") → prefix × suffix: one pass left-to-right, one pass right-to-left. Store one direction in the output and keep the other as a running variable for O(1) extra space. Same shape as prefix sums, just with instead of +.