← Practice · Backtracking
Combination Sum Medium
Given an array of distinct positive integers candidates and a target, return all unique combinations of candidates that sum to target. The same number may be used any number of times. Two combinations are different if the count of some number differs. Return in any order.
Examples
candidates = [2,3,6,7], target = 7 -> [[2,2,3],[7]]candidates = [2], target = 1 -> []
Define a function named combinationSum in JavaScript.
00:00▶ Visualize
JavaScript · Tab indents · Ctrl/⌘+Enter runs the tests