Enumerate All Member Choices from Distinct Values

Quick Overview

Enumerate the full power set of distinct integers without duplicate member sets or a prescribed collection order.

Enumerate All Member Choices from Distinct Values

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

### Problem Return every subset of the distinct integers in `nums`, including the empty subset and the full set. Include each choice of members once. The collection may be returned in any order; rearranging the members of a subset does not create a different subset. ```cpp vector<vector<int>> subsets(vector<int>& nums); ``` ### Examples ```text Input: nums = [-2,4] One valid output: [[],[4],[-2,4],[-2]] ``` ```text Input: nums = [7] One valid output: [[7],[]] ``` ### Constraints & Assumptions - `1 <= nums.length <= 10`. - Every entry is between -10 and 10, inclusive, and all entries are distinct. - Return subsets rather than permutations or only subsets of one size. ### Clarifying Questions to Ask - Is the empty subset included? Yes. - Does the returned collection need a prescribed order? No. ```hint Account for every choice Each input element may belong to a subset or be absent. The final collection must represent every member choice exactly once. ``` ### What a Strong Answer Covers - Complete enumeration without duplicate member sets. - The empty and full subsets and a representation that preserves each selected value. - Time and memory costs that include the returned collection. ### Follow-up Questions - How many subsets must be returned for an input of length `n`? - How can a checker compare two correct collections in different orders?

Overview: Enumerate the full power set of distinct integers without duplicate member sets or a prescribed collection order.

Amazon logo
Amazon
Source window: 0–3 months · as of Oct 21, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Problem

Return every subset of the distinct integers in nums, including the empty subset and the full set. Include each choice of members once. The collection may be returned in any order; rearranging the members of a subset does not create a different subset.

vector<vector<int>> subsets(vector<int>& nums);

Examples

Input: nums = [-2,4]
One valid output: [[],[4],[-2,4],[-2]]
Input: nums = [7]
One valid output: [[7],[]]

Constraints & Assumptions

  • 1 <= nums.length <= 10 .
  • Every entry is between -10 and 10, inclusive, and all entries are distinct.
  • Return subsets rather than permutations or only subsets of one size.

Clarifying Questions to Ask Guidance

  • Is the empty subset included? Yes.
  • Does the returned collection need a prescribed order? No.

What a Strong Answer Covers Guidance

  • Complete enumeration without duplicate member sets.
  • The empty and full subsets and a representation that preserves each selected value.
  • Time and memory costs that include the returned collection.

Follow-up Questions Guidance

  • How many subsets must be returned for an input of length n ?
  • How can a checker compare two correct collections in different orders?