Home
Log in
DescriptionSubmissionsSolution
DescriptionSubmissionsSolution
Loading...

Log in to run or submit

candidates =
target =

Codey

Practise coding problems, test your solutions and track your progress.

Explore

  • Problems
  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

© 2026 Codey. Personal learning project.

Solution
Updated: 2026-02-23

Idea

Backtrack with choices to reuse a candidate any number of times.

Approach

Sort candidates. DFS with (index i, remaining rem):

  • Take candidates[i] (stay at i to allow reuse).
  • Or skip it (move to i+1).

Why it works

This explores all non-decreasing combinations; staying at i enables unlimited reuse without permutations.

Code
Loading...
Complexity
Time: Exponential (output-sensitive)
Space: O(target) recursion depth worst-case
Solution
Updated: 2026-02-23

Idea

Backtrack with choices to reuse a candidate any number of times.

Approach

Sort candidates. DFS with (index i, remaining rem):

  • Take candidates[i] (stay at i to allow reuse).
  • Or skip it (move to i+1).

Why it works

This explores all non-decreasing combinations; staying at i enables unlimited reuse without permutations.

Code
Loading...
Complexity
Time: Exponential (output-sensitive)
Space: O(target) recursion depth worst-case