LeetCodechevron_rightSolve patternschevron_rightbacktracking pruning
schemaReusable solving pattern

backtracking pruning Pattern

Pattern hubs are for building transferable solving frames. Learn the recognition signals first, then drill state definition, update rules, and edge explanation until the pattern feels stable.

database52 problemstune2/34/16 difficulty mixcategory6 linked topics

Pattern brief

Recognize first

Do you handle empty input correctly to avoid unnecessary recursion?

Solve rhythm

State the active state and invariant first, explain how each update preserves them, then pressure-test with counterexamples.

Most common miss

Failing to prune paths when the current combination exceeds the input length, leading to unnecessary recursion.

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

Problem bank

backtracking pruning pattern bank

Start by scanning with search or difficulty filters, then narrow by linked topics. The bank continues loading inside its own container so the page stays readable.

Progressive pattern bank

Use it to build pattern understanding first, then expand into the full corpus.

hourglass_bottomScroll inside to continue
search
tuneDifficulty
categoryTopic focus

Showing 24 / 52 problems

+24 per load
#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

swap_vertScroll inside the bank to auto-load more

Continue by topic

Once the pattern itself feels familiar, move back into concrete topic hubs so you can separate the pattern from the changing problem context.

route

Guided Practice Path

AI recommends problems by your level and tracks your progress.

Start Guided Patharrow_forward
Backtracking search with pruning LeetCode Pattern: 52 Solutions