Recursion and Backtracking Python practice problems
Base cases, call stacks, recursive structure, choice trees, pruning, and undoing choices safely.
Core concepts
Problem-solving patterns
- recursion · base case
- recursion · digits
- divide and conquer · power
- Euclid · recursion
- binary search · recursion
What this topic builds
Learn the idea once, use it across the exercises, and explain why your approach works.
All 24 problems in this topic
Work from top to bottom to build the concept gradually.
- #219Compute factorial recursively: Recursive arrangement countBeginnerPremium
Use recursion to calculate seven factorial.
- #220Compute factorial recursively: Recursive base caseBeginnerPremium
Verify that the base case returns one for zero.
- #221Sum digits recursively: ChecksumIntermediatePremium
Calculate a simple digit checksum recursively.
- #222Sum digits recursively: Negative inputIntermediatePremium
Ignore the sign before summing a negative number's digits.
- #223Calculate integer power recursively: Large exponent efficientlyIntermediatePremium
Compute a power using logarithmic recursion.
- #224Calculate integer power recursively: Zero exponentIntermediatePremium
Any nonzero base raised to zero returns one.
- #225Find GCD recursively: Shared factorIntermediatePremium
Find the greatest common divisor of two related values.
- #226Find GCD recursively: Second input zeroAdvancedPremium
The base case returns the first value immediately.
- #227Binary search recursively: Found targetAdvancedPremium
Find the zero-based index of a target in a sorted catalog.
- #228Binary search recursively: Missing targetAdvancedPremium
Return -1 after the search range becomes empty.
- #229Check a palindrome recursively: Odd-length palindromeAdvancedPremium
Verify a word with one middle character.
- #230Check a palindrome recursively: Early mismatchAdvancedPremium
Stop and return False as soon as outer characters differ.
- #231Generate all permutations: Three-character arrangementsAdvancedPremium
List every ordering of three distinct task labels.
- #232Generate all permutations: Two-character arrangementsAdvancedPremium
Show the smallest nontrivial permutation set.
- #233Generate all subsets: Feature subsetsInterview-LevelPremium
List every subset of three numbered features.
- #234Generate all subsets: Single valueInterview-LevelPremium
A one-value set has the empty subset and one nonempty subset.
- #235Generate balanced parentheses: Three pairsInterview-LevelPremium
Generate every valid expression containing three pairs.
- #236Generate balanced parentheses: One pairInterview-LevelPremium
Generate the single valid expression for one pair.
- #237Count N-Queens solutions: Classic four-queen boardInterview-LevelPremium
Count valid arrangements on a 4-by-4 chessboard.
- #238Count N-Queens solutions: Five-queen boardInterview-LevelPremium
Count solutions for the next board size to exercise more branches.
- #239Sort with merge sort: General listInterview-LevelPremium
Apply a stable divide-and-conquer sort to mixed integers.
- #240Sort with merge sort: Duplicates and negativesInterview-LevelPremium
Preserve duplicates while ordering signed values.
- #241Sort with quicksort: Quicksort practiceInterview-LevelPremium
Sort a general list using recursive partitioning.
- #242Sort with quicksort: Many duplicate pivotsInterview-LevelPremium
Use the equal partition to group repeated values efficiently.