
4Sum
Four choices suggest an O(n^4) search. Sorting changes the last two choices into a controlled walk.
View solutionArticles whose authoritative difficulty is advanced.
Tagged articles
21 articles in this tag.

Four choices suggest an O(n^4) search. Sorting changes the last two choices into a controlled walk.
View solution
Repeated characters create the trap: different selections from s can produce the same visible text in t, and the problem still counts those selections…
View solution
Repeated subtraction computes division correctly, but it counts quotient units one at a time. Under interview constraints, that is the wrong scale of…
View solution
The table is easy to memorize and easy to misuse. The durable idea is simpler: track how far you have consumed each string, then let the final operation…
View solution
The array is not just input. Under the right invariant, it becomes its own presence map.
View solution
When both source strings can provide the next target character, a greedy pointer has to guess. Dynamic programming keeps both possibilities alive until the…
View solution
The hard part is rarely choosing a rectangle height. It is proving how far that height can extend.
View solution
Counting matching pairs is not enough. The pairs must form one contiguous, well-formed region, and valid regions can nest, touch, or be separated by an…
View solution
The heap is only half the solution. The real insight is maintaining exactly one valid frontier node per sorted list.
View solution
The hard part is not moving two pointers. It is preserving the target’s multiplicity while the window changes.
View solution
The key change from N-Queens is the output contract: you need one integer, so the search should retain only reversible constraints and count valid leaves.
View solution
The board is only the output surface. The real N-Queens solution is a depth-n search over column assignments, with three constraints checked before each…
View solution
The reliable way to solve Next Permutation is to stop thinking in four memorized steps. Read the suffix, identify where it is already maximal, then make…
View solution
Do not generate the permutations. Locate the block, choose its digit, and repeat.
View solution
A binary search tree has a structural invariant that is more useful than its parent-child relationships: inorder traversal visits values in sorted order.…
View solution
Reversing a linked-list segment is easy. Preserving everything on both sides of that segment is the real interview problem.
View solution
A line can contain the correct words and still be wrong: one space in the wrong gap, one missing trailing space, or full justification applied to the final…
View solution
The picture suggests moving inward from both ends. The proof requires more: finalize only the side whose limiting boundary is already certified.
View solution
The counting recurrence is only half the problem. To generate every tree, you must materialize every left/right subtree combination.
View solution
The shape is what you count; BST ordering is what makes each root split deterministic.
View solution
A decimal point and an exponent are easy to track. The hard part is proving that every numeric component actually contains the digits the grammar requires.
View solution