ExamAdda Logo

Subsets

Medium

Given an integer array nums of unique elements, return all possible subsets (the power set).

The solution set must not contain duplicate subsets.

You may return the subsets in any order.

Example 1

Input

nums = [1, 2, 3]

Output

[
    [],
    [1],
    [2],
    [1, 2],
    [3],
    [1, 3],
    [2, 3],
    [1, 2, 3]
]

Explanation

For three elements, every element can either be:

  • Included in the subset
  • Not included in the subset

Therefore, the total number of subsets is:

2³ = 8

Example 2

Input

nums = [0]

Output

[
    [],
    [0]
]

Explanation

The array contains one element, so there are two possible subsets:

[]
[0]

Constraints

1 <= nums.length <= 10
-10 <= nums[i] <= 10
All elements of nums are unique.
The answer must contain all possible subsets.

Hints:

Hint 1

For every element, there are two choices:

  • Include it.
  • Exclude it.
Hint 2

Use backtracking to explore both choices.

Author & Technical Reviewer

ExamAdda Technical Review Team

Technically reviewed by: ExamAdda Technical Review Team

Technical Reviewers, ExamAdda

Software engineers at ExamAdda who check every article's definitions, complexity claims and code examples before and after publishing.

Published

Aug 26, 2026

Last updated

Aug 26, 2026

Content Verification Methodology

Definitions and complexity claims were checked against authoritative computer-science references. Code examples were compiled and tested with standard, boundary and edge-case inputs.

Report a correction:editorial@examadda.org
Auto
Loading editor...
Input

Expected Output