Skip to main content
Back to problems
Leetcode
Medium
Backtracking
Recursion
Arrays
Combinatorics
Google
Meta
Subsets

Generate every possible subset of a given list of distinct integers.

Acceptance 0%
Problem Statement

Problem

Given a list of distinct integers, return the power set: every subset that can be formed from the list, including the empty subset and the full set.

A subset may be returned in any order, but each subset should contain elements in the same relative order as they appear in the input.

Goal

Produce all 2n2^n subsets without duplicates.

Input Format

  • A list nums of distinct integers.
  • nums.length = n.
  • Each element may be positive, negative, or zero.

Output Format

  • Return a list of all subsets of nums.
  • Each subset is represented as a list of integers.
  • The collection of subsets may be in any order.

Constraints

  • 0n100 \le n \le 10 is a reasonable interview-scale assumption.
  • Elements are distinct.
  • The total number of subsets is 2n2^n.
Examples
Sample cases returned by the problem API.

Example 1

Input

nums = [1,2,3]

Output

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

Explanation

Each element can either be present or absent, producing 23=82^3 = 8 subsets.

Example 2

Input

nums = [0]

Output

[[],[0]]

Explanation

There are two subsets: the empty subset and the subset containing the single element.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.