Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    Practice problems / Combination sum

    Combination sum

    Mediumbacktrackingrecursionarray

    candidates holds distinct positive numbers. Return every combination summing to target, where each number may repeat any number of times. A combination is a set (order inside it doesn't matter), and the order of combinations doesn't matter either.

    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]]

    Example 3

    Input:  candidates = [2], target = 1
    Output: []

    Constraints

    • 1 ≤ candidates.length ≤ 30
    • 2 ≤ candidates[i] ≤ 40, distinct
    • 1 ≤ target ≤ 40

    Submit checks your solution against 9 tests, including hidden ones.

    /**
     * @param {int[]} candidates
     * @param {int} target
     * @return {int[][]}
     */
    function combinationSum(candidates, target) {
      
    }
    
    Sign in to run
    SeaCode

    Learn to code for real, online or at our branch in front of Cairo University, Giza.

    Learn

    • All courses
    • Interactive tutorials
    • Interview practice problems
    • Mock interview
    • Learning tracks
    • Code Arena
    • Workshops & Events
    • Knowledge library
    • Team projects

    Your account

    • Log in
    • Sign up
    • Learning plan
    • Certificates
    • Site map

    Contact us

    • WhatsApp
    • 010 9094 1104
    • In front of Cairo University, Giza

    © 2026 SeaCode. All rights reserved.