You are given an array of integers that may contain duplicates and a target value target. Your task is to find all unique combinations where the chosen numbers sum to the target.
Example 1
Input: arr[] = [3], target = 3
Output: [3]
Explanation: The single element itself equals the target.
Example 2
Input: arr[] = [1 1 2 5], target = 3
Output: [1 2]
Explanation: Elements are chosen once, and duplicate combinations are avoided.
Example 3
Input: arr[] = [10 1 2 7 6 1 5], target = 8
Output: [1 1 6] [1 2 5] [1 7] [2 6]
Explanation: Different unique selections of numbers add up to 8, and repeated combinations are not included.
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
10 1 2 7 6 1 5 8
17 125 26 116
2 5 2 1 2 5
5 122