Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

Combination Sum

Medium

Topics
ArrayBacktracking

Given distinct positive integers candidates and a target, return all unique combinations that sum to target. A candidate may be reused unlimited times.

Example 1

Input:  candidates = [2,3,6,7], target = 7
Output: [[2,2,3],[7]]

Example 2

Input:  candidates = [2,3,5], target = 8
Output: [[2,2,2,2],[2,3,3],[3,5]]

Constraints

  • 1 <= candidates.length <= 30
  • All candidates are distinct positive integers.
  • 1 <= target <= 40
Run ⌘' · Submit ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access