Backtracking LeetCode Problems: All 105,
With Python Solutions

Every problem in this library that LeetCode tags Backtracking. 86 of them carry a complete Python solution, a worked example and the time and space complexity of the approach.

Easy
3
Medium
71
Hard
31
1 pattern

How Backtracking problems are solved

A tag names the subject, not the method. These pattern hubs cover the techniques that actually solve Backtracking problems — each one explains the approach, gives a Python template and states its complexity.

Eyes only

When the Backtracking problem arrives live.

In the live round, Stealth Interview reads the problem off your screen, returns a working solution with a step-by-step explanation and its time and space complexity, and transcribes what the interviewer says. It's a desktop app for macOS and Windows, invisible to screen sharing.

Backtracking problems by difficulty

Problems with a complete Python solution are listed first, then by ascending problem number.

Easy (3)

Easy problems
No.Problem
0257Binary Tree Paths
0401Binary Watch
1863Sum of All Subset XOR Totals

Medium (71)

Medium problems
No.Problem
0017Letter Combinations of a Phone Number
0022Generate Parentheses
0039Combination Sum
0040Combination Sum II
0046Permutations
0047Permutations II
0077Combinations
0078Subsets
0079Word Search
0089Gray Code
0090Subsets II
0093Restore IP Addresses
0095Unique Binary Search Trees II
0113Path Sum II
0131Palindrome Partitioning
0216Combination Sum III
0306Additive Number
0357Count Numbers with Unique Digits
0473Matchsticks to Square
0491Non-decreasing Subsequences
0494Target Sum
0526Beautiful Arrangement
0638Shopping Offers
0698Partition to K Equal Sum Subsets
0756Pyramid Transition Matrix
0784Letter Case Permutation
0797All Paths From Source to Target
0816Ambiguous Coordinates
0842Split Array into Fibonacci Sequence
0949Largest Time for Given Digits
0967Numbers With Same Consecutive Differences
0988Smallest String Starting From Leaf
1079Letter Tile Possibilities
1219Path with Maximum Gold
1238Circular Permutation in Binary Representation
1239Maximum Length of a Concatenated String with Unique Characters
1286Iterator for Combination
1415The k-th Lexicographical String of All Happy Strings of Length n
1593Split a String Into the Max Number of Unique Substrings
1718Construct the Lexicographically Largest Valid Sequence
1774Closest Dessert Cost
1849Splitting a String Into Descending Consecutive Values
1947Maximum Compatibility Score Sum
1980Find Unique Binary String
1986Minimum Number of Work Sessions to Finish the Tasks
2002Maximum Product of the Length of Two Palindromic Subsequences
2044Count Number of Maximum Bitwise-OR Subsets
2048Next Greater Numerically Balanced Number
2178Maximum Split of Positive Even Integers
2212Maximum Points in an Archery Competition
2305Fair Distribution of Cookies
2375Construct Smallest Number From DI String
2397Maximum Rows Covered by Columns
2597The Number of Beautiful Subsets
2698Find the Punishment Number of an Integer
2708Maximum Strength of a Group
2767Partition String Into Minimum Beautiful Substrings
0254Factor CombinationsPremium
0267Palindrome Permutation IIPremium
0291Word Pattern IIPremium
0294Flip Game IIPremium
0320Generalized AbbreviationPremium
0351Android Unlock PatternsPremium
0681Next Closest TimePremium
1066Campus Bikes IIPremium
1087Brace ExpansionPremium
1215Stepping NumbersPremium
1258Synonymous SentencesPremium
2152Minimum Number of Lines to Cover PointsPremium
2664The Knight’s TourPremium
2992Number of Self-Divisible PermutationsPremium

Hard (31)

Hard problems
No.Problem
0037Sudoku Solver
0051N-Queens
0052N-Queens II
0126Word Ladder II
0140Word Break II
0212Word Search II
0282Expression Add Operators
0301Remove Invalid Parentheses
067924 Game
0691Stickers to Spell Word
0773Sliding Puzzle
0980Unique Paths III
0996Number of Squareful Arrays
1096Brace Expansion II
1240Tiling a Rectangle with the Fewest Squares
1255Maximum Score Words Formed by Letters
1307Verbal Arithmetic Puzzle
1467Probability of a Two Boxes Having The Same Number of Distinct Balls
1601Maximum Number of Achievable Transfer Requests
1655Distribute Repeating Integers
1723Find Minimum Time to Finish All Jobs
1799Maximize Score After N Operations
2014Longest Subsequence Repeated k Times
2056Number of Valid Move Combinations On Chessboard
2065Maximum Path Quality of a Graph
2151Maximum Good People Based on Statements
0411Minimum Unique Word AbbreviationPremium
0425Word SquaresPremium
0465Optimal Account BalancingPremium
0489Robot Room CleanerPremium
1088Confusing Number IIPremium