Skip to interview prep
Apexed

49. Subsets (Power Set)

MediumRecursion & backtracking

Given distinct integers nums, return every subset. Sort the numbers inside each subset ascending, and sort the list of subsets by length, then lexicographically.

Example 1

Input: nums = [1, 2, 3]
Output: [[], [1], [2], [3], [1, 2], [1, 3], [2, 3], [1, 2, 3]]

Constraints

  • 0 ≤ nums.length ≤ 10
  • Values are distinct

Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor

Run checks these cases; the expected output comes from the reference solution. Submit judges all 4 hidden and sample tests.

Code runs only in your browser in an isolated sandbox. Progress and submissions are saved on this device.

Subsets (Power Set) — coding interview practice — Apexed