loading

Combinations — Step-by-Step Visualization

mediumLeetCode #77Backtracking

Return all possible combinations of k numbers from [1, n].

Algorithm Pattern

Backtracking

Key Idea

Choose numbers in increasing order. Stop when combo length reaches k.

Step-by-Step Approach

  1. For each number from start to n
  2. Add to current combo
  3. If len==k, record result
  4. Else recurse with next start
  5. Backtrack: pop last element

Related Problems