Solvarch
DSA ProblemsProgressPlanRoadmapsReviewCheat SheetsCompaniesSystem DesignCS FundamentalsQuestion Bank
Theme
Problems

Subsets II

Medium
backtrackingrecursionsorting

Given an array of integers that may contain duplicates, return all possible subsets — without any duplicate subsets in the output.

Input: one line of space-separated integers. Output: one subset per line, elements in ascending order (the empty subset prints as an empty line). Subsets may be produced in any order — the template prints them canonically.

Example 1
Input:
1 2 2
Output:

1
1 2
1 2 2
2
2 2
Example 2
Input:
0
Output:

0

Constraints

  • 1 ≤ nums.length ≤ 10
  • -10 ≤ values ≤ 10 (duplicates allowed)
Watch a video walkthrough

Run your code against the sample tests, or Submit to run the full suite.