LeetCodechevron_rightbacktracking pruning

backtracking pruning Pattern

52 problems

Pattern pages help build reusable solving frames. Identify signals first, then explain state, transition, and edge handling.

Recognition Signals

  • Do you handle empty input correctly to avoid unnecessary recursion?
  • Can you explain how pruning prevents generating invalid or partial combinations?
  • Checks if you handle repeated use of candidates correctly.

Solve Flow

  1. 1. Define the active state/window.
  2. 2. Update state while preserving invariants.
  3. 3. Validate with edge-heavy examples.

Common Misses

  • Failing to prune paths when the current combination exceeds the input length, leading to unnecessary recursion.
  • Failing to prune when the path sum exceeds the target, causing unnecessary recursion.
  • Not sorting candidates first, which complicates duplicate skipping.

Recommended Ladder

#TitleDifficulty
17

Letter Combinations of a Phone Number

Generate all letter combinations a digit string can represent using backtracking with pruning, leveraging hash table map…

Medium
39

Combination Sum

Find all unique combinations of numbers from a distinct array that sum to a target using controlled backtracking search.

Medium
40

Combination Sum II

Find all unique combinations of numbers that sum to a target using backtracking with careful pruning to avoid duplicates…

Medium
46

Permutations

Generate all possible orderings of a distinct integer array using backtracking search with careful pruning to avoid dupl…

Medium
47

Permutations II

Generate all unique permutations of an array containing duplicates using backtracking and pruning to avoid repeated sequ…

Medium
51

N-Queens

Solve the N-Queens problem using backtracking with pruning, exploring all valid board placements while avoiding conflict…

Hard
52

N-Queens II

Solve the N-Queens II problem using backtracking with pruning to efficiently count all valid placements for n queens on …

Hard
77

Combinations

Generate all combinations of k numbers from the range [1, n] using backtracking and pruning.

Medium
78

Subsets

Generate all subsets of a set of unique integers using backtracking with pruning to avoid duplicates.

Medium
79

Word Search

Solve Word Search with backtracking by exploring adjacent cells to match a target word in a grid.

Medium
89

Gray Code

Generate an n-bit Gray Code sequence using backtracking with pruning and bit manipulation techniques.

Medium
90

Subsets II

Subsets II problem asks to generate unique subsets from an array with possible duplicates using backtracking search with…

Medium
93

Restore IP Addresses

Restore all valid IP addresses from a string using backtracking with pruning, avoiding invalid segments or leading zeros…

Medium
126

Word Ladder II

Find all shortest transformation sequences from beginWord to endWord using a dictionary, leveraging backtracking search …

Hard
212

Word Search II

Solve the Word Search II problem using backtracking with pruning to find all words on a board of characters.

Hard
216

Combination Sum III

Find all unique combinations of k numbers adding to n using efficient backtracking with pruning in arrays.

Medium
282

Expression Add Operators

Expression Add Operators is solved with backtracking that builds multi-digit operands and tracks multiplication preceden…

Hard
301

Remove Invalid Parentheses

Remove the minimum number of invalid parentheses to generate all possible valid strings efficiently using backtracking a…

Hard
306

Additive Number

Additive Number is solved by trying the first two splits, then pruning aggressively while verifying each required sum in…

Medium
401

Binary Watch

Binary Watch involves generating possible times on a binary watch given a number of turned-on LEDs.

Easy
679

24 Game

Solve the 24 Game by arranging four card numbers using arithmetic operators and parentheses to reach exactly 24 efficien…

Hard
784

Letter Case Permutation

Letter Case Permutation involves generating all possible strings by changing the case of each letter in a given string.

Medium
816

Ambiguous Coordinates

Find all valid 2D coordinate possibilities for an ambiguous input string using backtracking and pruning techniques.

Medium
842

Split Array into Fibonacci Sequence

This problem challenges you to split a string into a Fibonacci-like sequence using backtracking and pruning.

Medium
949

Largest Time for Given Digits

Given four digits, determine the latest valid 24-hour time possible using each digit exactly once with backtracking.

Medium
967

Numbers With Same Consecutive Differences

Generate all n-digit numbers where consecutive digits differ by k using efficient backtracking and BFS techniques.

Medium
980

Unique Paths III

Solve the Unique Paths III problem using backtracking search with pruning to count 4-directional paths covering all empt…

Hard
1079

Letter Tile Possibilities

Compute all unique non-empty sequences from given letter tiles using backtracking search with pruning efficiently.

Medium
1219

Path with Maximum Gold

Find the path with the maximum gold in a grid with backtracking and pruning techniques to maximize the gold collected.

Medium
1238

Circular Permutation in Binary Representation

Generate a circular permutation from a range of numbers using backtracking and bit manipulation.

Medium
1239

Maximum Length of a Concatenated String with Unique Characters

Find the maximum length of a concatenated string from an array with all unique characters using backtracking search with…

Medium
1240

Tiling a Rectangle with the Fewest Squares

Tiling a Rectangle with the Fewest Squares problem asks for the minimum number of squares required to cover a rectangle …

Hard
1286

Iterator for Combination

Implement an iterator that generates all combinations of a given length using efficient backtracking with pruning.

Medium
1307

Verbal Arithmetic Puzzle

Check if a verbal arithmetic equation can be solved using a valid digit-letter mapping.

Hard
1415

The k-th Lexicographical String of All Happy Strings of Length n

Given n and k, find the k-th lexicographical happy string of length n using backtracking search with pruning.

Medium
1593

Split a String Into the Max Number of Unique Substrings

Maximize unique substrings in a string using backtracking with pruning and hash tables to track substrings.

Medium
1601

Maximum Number of Achievable Transfer Requests

Find the maximum number of achievable transfer requests between buildings with constraints on net employee transfers.

Hard
1718

Construct the Lexicographically Largest Valid Sequence

Construct the Lexicographically Largest Valid Sequence problem involves finding the largest sequence with backtracking a…

Medium
1849

Splitting a String Into Descending Consecutive Values

Check if a string of digits can be split into descending consecutive values where the difference between them is 1.

Medium
1863

Sum of All Subset XOR Totals

Compute the sum of all subset XOR totals using a backtracking search with pruning for arrays of small size.

Easy
2014

Longest Subsequence Repeated k Times

Find the longest subsequence repeated k times in a string using backtracking search with pruning.

Hard
2044

Count Number of Maximum Bitwise-OR Subsets

Determine the number of non-empty subsets that achieve the maximum bitwise OR using efficient backtracking and pruning s…

Medium
2048

Next Greater Numerically Balanced Number

Find the smallest numerically balanced number greater than a given integer using backtracking search and pruning.

Medium
2056

Number of Valid Move Combinations On Chessboard

Given a set of pieces on a chessboard, calculate the number of valid move combinations without overlap using backtrackin…

Hard
2065

Maximum Path Quality of a Graph

Calculate the maximum path quality in a graph using backtracking and pruning to optimize node visits within time limits …

Hard
2151

Maximum Good People Based on Statements

Determine the maximum number of good people in a group given mutual statements, using precise backtracking with pruning.

Hard
2178

Maximum Split of Positive Even Integers

Determine the largest set of unique positive even integers that sum to a given finalSum using backtracking and greedy se…

Medium
2212

Maximum Points in an Archery Competition

In the "Maximum Points in an Archery Competition" problem, Bob aims to maximize his score while respecting Alice's arrow…

Medium
2397

Maximum Rows Covered by Columns

Select exactly numSelect columns from a binary matrix to maximize rows where all ones are covered efficiently using back…

Medium
2698

Find the Punishment Number of an Integer

Find the punishment number of a given integer using backtracking search with pruning.

Medium
3211

Generate Binary Strings Without Adjacent Zeros

Generate all binary strings of length n without adjacent zeros using backtracking search with pruning for efficient enum…

Medium
3348

Smallest Divisible Digit Product II

Find the smallest zero-free number at least as large as num whose digits multiply to a product divisible by t using care…

Hard

Related Topics

Backtracking search with pruning LeetCode Pattern: 52 Solutions