Generate all subsets of a distinct-integer array except the full set

Quick Overview

Return every subset of an array of distinct integers except the full set, with elements ascending inside each subset and the list sorted lexicographically. Tests bitmask or backtracking enumeration of the power set, exact handling of the excluded case, and control of output order.

Generate all subsets of a distinct-integer array except the full set

Company: Miro

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

Given an integer array `nums` of unique elements, return all possible subsets (the power set), **excluding** the full set itself. The solution set must not contain duplicate subsets. Return the solution with each subset's elements in ascending order, and the outer list sorted lexicographically. ### Function Signature ```python def subsets_without_full(nums: list[int]) -> list[list[int]]: ``` ### Rules - The empty subset is included. Only the subset that contains every element of `nums` is left out. - Lexicographic order compares two subsets element by element from the left, the way Python compares lists. A subset that is a prefix of a longer one comes first, so `[1]` comes before `[1, 2]`. - The order of `nums` in the input does not change the output. ### Constraints - `1 <= len(nums) <= 10` - `-10 <= nums[i] <= 10` - All the numbers of `nums` are unique. ### Examples ```text Input: nums = [1, 2, 3] Output: [[], [1], [1, 2], [1, 3], [2], [2, 3], [3]] ``` These are all subsets of `[1, 2, 3]` except `[1, 2, 3]` itself: seven of the eight, in lexicographic order. ```text Input: nums = [0] Output: [[]] ``` The only subsets of `[0]` are `[]` and `[0]`. Excluding the full set `[0]` leaves just `[]`. ```text Input: nums = [2, -5] Output: [[], [-5], [2]] ``` The full set is `[-5, 2]` once its elements are sorted, and it is dropped. Of the rest, `[]` comes first because it is a prefix of every list, then `[-5]` comes before `[2]` because `-5 < 2`.

Overview: Return every subset of an array of distinct integers except the full set, with elements ascending inside each subset and the list sorted lexicographically. Tests bitmask or backtracking enumeration of the power set, exact handling of the excluded case, and control of output order.

Miro logo
Miro
Nov 24, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

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

The solution set must not contain duplicate subsets. Return the solution with each subset's elements in ascending order, and the outer list sorted lexicographically.

Function Signature

def subsets_without_full(nums: list[int]) -> list[list[int]]:

Rules

  • The empty subset is included. Only the subset that contains every element of nums is left out.
  • Lexicographic order compares two subsets element by element from the left, the way Python compares lists. A subset that is a prefix of a longer one comes first, so [1] comes before [1, 2] .
  • The order of nums in the input does not change the output.

Constraints

  • 1 <= len(nums) <= 10
  • -10 <= nums[i] <= 10
  • All the numbers of nums are unique.

Examples

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

These are all subsets of [1, 2, 3] except [1, 2, 3] itself: seven of the eight, in lexicographic order.

Input: nums = [0]
Output: [[]]

The only subsets of [0] are [] and [0]. Excluding the full set [0] leaves just [].

Input: nums = [2, -5]
Output: [[], [-5], [2]]

The full set is [-5, 2] once its elements are sorted, and it is dropped. Of the rest, [] comes first because it is a prefix of every list, then [-5] comes before [2] because -5 < 2.