Recursion and Backtracking Python practice problems
Understand base cases, shrinking subproblems, recursive search, and choice-and-undo backtracking.
Core concepts
Problem-solving patterns
- Base case → make a smaller choice → recurse → undo if needed
Reported company tags
All 20 problems in this topic
Work from top to bottom to build the concept gradually.
- #141Compute factorial recursively: Recursive arrangement countIntermediatePremium
Use recursion to calculate seven factorial.
- #142Compute factorial recursively: Recursive base caseIntermediatePremium
Verify that the base case returns one for zero.
- #143Sum digits recursively: ChecksumIntermediatePremium
Calculate a simple digit checksum recursively.
- #144Sum digits recursively: Negative inputIntermediatePremium
Ignore the sign before summing a negative number's digits.
- #145Calculate integer power recursively: Large exponent efficientlyIntermediatePremium
Compute a power using logarithmic recursion.
- #146Calculate integer power recursively: Zero exponentIntermediatePremium
Any nonzero base raised to zero returns one.
- #147Find GCD recursively: Shared factorIntermediatePremium
Find the greatest common divisor of two related values.
- #148Find GCD recursively: Second input zeroIntermediatePremium
The base case returns the first value immediately.
- #149Binary search recursively: Found targetIntermediatePremium
Find the zero-based index of a target in a sorted catalog.
- #150Binary search recursively: Missing targetIntermediatePremium
Return -1 after the search range becomes empty.
- #151Check a palindrome recursively: Odd-length palindromeIntermediatePremium
Verify a word with one middle character.
- #152Check a palindrome recursively: Early mismatchIntermediatePremium
Stop and return False as soon as outer characters differ.
- #153Generate all permutations: Three-character arrangementsIntermediatePremium
List every ordering of three distinct task labels.
- #154Generate all permutations: Two-character arrangementsIntermediatePremium
Show the smallest nontrivial permutation set.
- #155Generate all subsets: Feature subsetsIntermediatePremium
List every subset of three numbered features.
- #156Generate all subsets: Single valueIntermediatePremium
A one-value set has the empty subset and one nonempty subset.
- #157Generate balanced parentheses: Three pairsIntermediatePremium
Generate every valid expression containing three pairs.
- #158Generate balanced parentheses: One pairIntermediatePremium
Generate the single valid expression for one pair.
- #159Count N-Queens solutions: Classic four-queen boardIntermediatePremium
Count valid arrangements on a 4-by-4 chessboard.
- #160Count N-Queens solutions: Five-queen boardIntermediatePremium
Count solutions for the next board size to exercise more branches.