Bootcamps
Masterclasses
Menu
Courses
Account
Login / Sign Up

Combination Sum II

Medium Acceptance 76% Points 30

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.

Examples
Example 1

Example 1

Input: arr[] = [3], target = 3

Output: [3]

Explanation: The single element itself equals the target.

Example 2

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

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.

Constraints
  • 1 = n = 20
  • 1 = arr[i] = 50
  • 1 = target = 100
Topics
Recursion
Companies
Apple Samsung
Added 19 Jul 2026 76% acceptance
Ln 1, Col 1Sign in to save your code
10 1 2 7 6 1 5
8
17 125 26 116