Given a collection of candidate numbers candidates (which may contain duplicates) and a target number target, find all unique combinations in candidates where the candidate numbers sum to target. Each number in candidates may only be used once in the combination. Note: The solution set must not contain duplicate combinations.
Example 1
Input: candidates = [10,1,2,7,6,1,5], target = 8
Output: [[1,1,6],[1,2,5],[1,7],[2,6]]
Explanation: The combinations that reach 8 are 1 + 1 + 6 (using both 1s), 1 + 2 + 5, 1 + 7 and 2 + 6. Using either 1 in 1 + 7 gives the same combination, so it is listed once.
Example 2
Input: candidates = [2,5,2,1,2], target = 5
Output: [[1,2,2],[5]]
Explanation: The combinations that reach 5 are 1 + 2 + 2 and 5. There are three 2s, but choosing different ones gives the same combination, so it appears once.
Example 3
Input: candidates = [1], target = 1
Output: [[1]]
Explanation: The single candidate 1 equals the target, so [[1]] is the only combination.
Sort the candidates so duplicates are adjacent and pruning is possible. Each element may be used once (recurse from i+1), and at each level skip a value equal to its left neighbour to avoid duplicate combinations.
Run checks all cases above. Submit evaluates all test cases.