Combination Sum II

Advanced

Combination Sum II

Help your friends organize a fun treasure hunt! They're excited to find all possible ways to reach the exact amount of treasure they need. Given a list of potential treasures (as numbers) and a desired sum, your task is to figure out all unique combinations where the treasure can be exactly equal to the desired sum. Each treasure can be used just once!

The challenge for you is to write a function combination_sum_ii that takes a list of integers (treasures) and a target integer, and returns all the unique combinations of numbers from the list that sums up to the target. Remember, each number in the list can only be used once in each combination.

Here's an example:

combination_sum_ii([10, 1, 2, 7, 6, 1, 5], 8) # Output: [[1, 1, 6], [1, 2, 5], [1, 7], [2, 6]]

Another example:

combination_sum_ii([2, 5, 2, 1, 2], 5) # Output: [[1, 2, 2], [5]]

Doesn't that sound like a fun puzzle?

Let your mind come up with clever ways to combine the numbers. Good luck with the treasure hunt adventure!

Geek
Inputs

Arg 1:

[10,1,2,7,6,1,5]

Arg 2:

8
Expected Output
[[1, 1, 6], [1, 2, 5], [1, 7], [2, 6]]
Actual Output
Combination Sum II [advanced] | Coding for Kids