Combination Sum II
Asked in the Coding round stage. One of the five timed coding-round questions.
Given an array candidates and integer target, return all unique combinations whose values sum to target. Each array element may be used at most once. The output may be returned in any order.
Example 1: candidates = [10,1,2,7,6,1,5], target = 8 returns [[1,1,6],[1,2,5],[1,7],[2,6]].
Example 2: candidates = [2,5,2,1,2], target = 5 returns [[1,2,2],[5]].
Constraints: 1 <= len(candidates) <= 100, 1 <= candidates[i] <= 50, and 1 <= target <= ก50.
def combination_sum2(candidates, target):