Combination Sum [Medium] — Backtracking with Pruning
Find all unique combinations that sum to a target, using backtracking with candidate reuse allowed.
webcoderspeed.com
33 articles
Find all unique combinations that sum to a target, using backtracking with candidate reuse allowed.
Generate all permutations of distinct integers using in-place swap backtracking.
Generate the power set of distinct integers using backtracking or bitmask enumeration.
Find all unique combinations that sum to target where each number may be used once, skipping duplicates at each recursion level.
Search for a word in a 2D grid using DFS backtracking with in-place visited marking.
Generate all unique subsets from an array with duplicates by sorting and skipping repeated elements at each recursion level.
Search for a word in a grid by moving to adjacent cells without reuse. DFS with backtracking: mark visited, recurse, unmark.
Find all paths from node 0 to node n-1 in a DAG. DFS with backtracking: explore each path, add to results when destination reached.
Find ALL shortest transformation sequences. BFS builds layer map, DFS reconstructs all paths backwards from endWord to beginWord.
Collect all root-to-leaf paths with a given sum using DFS backtracking, appending and removing the current node.
Complete backtracking reference: universal template, 7 pattern recognition cues, complexity guide, and top 30 interview problems.
Color a graph with m colors (no adjacent same color) and find Hamiltonian paths using backtracking with neighbor constraint checking.
Remove minimum invalid parentheses to produce all valid results. BFS approach for minimum removals, DFS for complete enumeration.
Solve Beautiful Arrangement and similar constraint-based permutation problems with backtracking and precomputed valid positions.
Compare backtracking and DP approaches for subset sum: when to use each, conversion to knapsack, and bitset optimization.
Solve tiling (domino, triomino) and optimal string splitting problems combining backtracking insight with DP optimization.
Solve the Knight's Tour problem and maze path finding using backtracking with Warnsdorff heuristic for dramatic speedup.
Solve partition backtracking problems: equal sum subset (NP-hard, backtrack with pruning) and k equal sum subsets.
Generate valid IP addresses from digit strings and all sentence segmentations with word break backtracking.
Generate all expressions by inserting +, -, * between digits to reach target. Track running value and last operand for multiplication.
Partition a string into all-palindrome substrings using backtracking with O(n^2) precomputed palindrome DP table for O(1) checks.
Generate all letter combinations from phone number digits using backtracking. Classic tree exploration with fixed branching factor.
Search for words in a character grid using DFS backtracking. Word Search II uses a Trie for simultaneous multi-word search.
Generate all valid parentheses combinations of length 2n using open/close count tracking. Classic backtracking interview problem.
Solve a 9x9 Sudoku board with backtracking enhanced by constraint propagation (arc consistency) for dramatic pruning.
Solve the N-Queens problem with backtracking using column/diagonal conflict tracking. O(n!) with early pruning.
Generate all k-combinations and find combinations summing to target. Master the start-index pattern to avoid duplicates.
Generate all n! permutations using backtracking with used[] array or in-place swap. Handles duplicates by sorting + skipping.
Generate all 2^n subsets of a set using backtracking (include/exclude) and bit masking. Handles duplicates with sorting + skip.
Master recursion and backtracking for DSA interviews: 7 core patterns, time complexity analysis, pruning strategies, and top 30 problems.
Word Search I and II solved with DFS backtracking. Word Search II uses a Trie to prune the search space from O(N·4^L) per word to O(N·4^L) total for all words.
Generate all combinations of well-formed parentheses of given n pairs using backtracking. Track open and close counts to prune invalid branches early.
Return all ways to segment a string into dictionary words. Combines DP validity check with DFS+memo backtracking to avoid TLE on valid inputs.