Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Combination Sum II

Medium Acceptance 76.00% Points 30.00

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.

Hints
Hint 1
N/A
Constraints
  • 1 = n = 20
  • 1 = arr[i] = 50
  • 1 = target = 100
Companies
Apple Samsung
Topics
Recursion
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions