
Generate Parentheses
Generate only prefixes that can still become valid. The balance state tells you exactly which branches to keep.
View solutionMaintain compact state representing multiple simultaneous rules that candidate values, placements, or paths must satisfy.
Tagged articles
8 articles in this tag.

Generate only prefixes that can still become valid. The balance state tells you exactly which branches to keep.
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 search tree is easy to recognize and easy to corrupt. Build one position at a time, choose an unused value, recurse, then undo exactly that choice.
View solution
The phrase “try digits and backtrack” is the easy part. The interview-grade solution keeps four representations synchronized: the board, row constraints,…
View solution
A Sudoku validator does not solve the puzzle. It tracks whether the digits already placed violate any row, column, or 3×3 box constraint.
View solution
A grid DFS can match the right letters and still be wrong. The missing piece is path-local state: mark a cell when you enter it, explore from that choice,…
View solution