EvalFrame Technical Mock Interviews & Coding Practice

Combination Sum

Medium · Recursion / Backtracking · Algorithm problem · all problems

Given an array of distinct integers `candidates` and a target integer `target`, return a list of all unique combinations of `candidates` where the chosen numbers sum to `target`. You may return the combinations in any order. The same number may be chosen from `candidates` an unlimited number of times. **Examples:** ```typescript combinationSum([2, 3, 6, 7], 7) // [[2, 2, 3], [7]] combinationSum([2, 3, 5], 8) // [[2, 2, 2, 2], [2, 3, 3], [3, 5]] combinationSum([2], 1) // [] ```

Solve It in the BrowserPractice Explaining It Out Loud

Optimal Approach

  • Time complexity: O(2^t)
  • Space complexity: O(t / min_candidate)

Branching tree explores valid combinations where maximum depth is target / min_candidate.

Follow-Up Questions Interviewers Ask About Combination Sum

  • How do you prevent duplicate combinations like [2, 3, 2] vs [2, 2, 3]?
    Pass start index i so each recursive step can only pick candidates from index i onwards.

Practice the full problem with execution, tests, and AI code review in the interactive lab — then rehearse explaining your solution in a live voice mock interview.