Skip to main content
← Problem catalogue Understand the pattern. Try it yourself. Review the solution. Practice this pattern →
Medium Backtracking High frequency Solution Available Practice Mode

Combination Sum LeetCode Solution

Tags: #Array #Backtracking

Approach Summary

Backtrack with start index. Can reuse same element (don't advance start). Prune when sum exceeds target.

Practice Mode 2 Progressive Approaches

Solve it yourself before revealing the code

DSA interviews test reasoning from brute force to optimal. Think through the constraints first.

Algorithmic Pattern

Master the Backtracking Pattern

View Pattern Guide →

Study the core invariant, step-by-step decision framework, and common interview traps for the Backtracking pattern.

Framework: Backtracking • Interview Prep: Tested at FAANG • Explore all Backtracking problems & invariants →

How to Recognize This Pattern

  • Unbounded element selection
  • Sum to target

Complexity Analysis

Time Complexity

O(n^(T/M))

Space Complexity

O(T/M)

Tags

Array Backtracking

Frequently Asked Questions

What is the optimal time and space complexity for Combination Sum?
The optimal solution for Combination Sum achieves O(n^(T/M)) runtime complexity and requires O(T/M) auxiliary space. Time complexity is O(2^(target / min(candidates))) in the worst case as the decision tree depth is bounded by target / min(candidates). Space complexity is O(target / min(candidates)) for the recursion stack and current path buffer.
How do I identify that Combination Sum requires the Backtracking pattern?
In technical interviews, look for key problem signals: Unbounded element selection; Sum to target. Recognizing these invariants allows you to bypass naive brute-force exhaustive search in favor of Backtracking strategy.
What critical edge cases must be handled in Combination Sum?
Essential edge cases to verify include: target is smaller than any candidate (returns empty list immediately); Single candidate that divides target (e.g. candidates = [2], target = 6; returns [[2, 2, 2]]); No combination adds up to target (returns empty list); Multiple valid combinations of varying lengths (e.g. [2, 3, 6, 7], target = 7; returns [[2, 2, 3], [7]]). Always walk through these scenarios with your interviewer before coding.
Which tech companies frequently ask Combination Sum?
Combination Sum is a Medium-difficulty question tagged with high recurrence. It is actively asked in technical screening and onsite interview loops at Amazon, Facebook, Adobe.
Buy me a coffee
Daily Practice
0/0