Enumerate Every Subset of Distinct Integers

Read the full interview experience this question came from →

Quick Overview

Enumerate the complete power set of distinct integers with choose-or-skip backtracking. Explain deterministic output ordering, copying mutable state, completeness, and exponential output size.

Enumerate Every Subset of Distinct Integers

Company: Pinduoduo

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

Given an array of distinct integers, return its complete power set: every subset, including the empty subset, exactly once. The report identifies the standard Subsets problem and explicitly permits ordinary enumeration without further optimization. ### Constraints and Clarifications All input values are unique. No numerical size bounds were reported. Subset ordering is not semantically important. For a deterministic practice representation, retain input order within each subset and enumerate decisions in input-index order, visiting exclusion before inclusion. This is output normalization for one complete set, not a request to choose one arbitrary valid subset. Empty input has the single subset []. ### Example For [1,2,3], the normalized enumeration is [[],[3],[2],[2,3],[1],[1,3],[1,2],[1,2,3]]. Other orderings describe the same power set, but the practice convention fixes serialization. ### What a Strong Answer Covers Use choose-or-skip recursion or an equivalent enumeration, copy each completed subset, and explain O(n*2^n) output-sensitive time with O(n) working space excluding output. ### Follow-up Questions - Why must the current subset be copied when adding it to the result? - What changes if the input contains duplicate values?

Overview: Enumerate the complete power set of distinct integers with choose-or-skip backtracking. Explain deterministic output ordering, copying mutable state, completeness, and exponential output size.

Read the full Pinduoduo Software Engineer interview experience this question came from

Pinduoduo logo
Pinduoduo
Nov 2, 2026
easySoftware EngineerTechnical ScreenCoding & Algorithms
0
0

Given an array of distinct integers, return its complete power set: every subset, including the empty subset, exactly once. The report identifies the standard Subsets problem and explicitly permits ordinary enumeration without further optimization.

Constraints and Clarifications

All input values are unique. No numerical size bounds were reported. Subset ordering is not semantically important. For a deterministic practice representation, retain input order within each subset and enumerate decisions in input-index order, visiting exclusion before inclusion. This is output normalization for one complete set, not a request to choose one arbitrary valid subset. Empty input has the single subset [].

Example

For [1,2,3], the normalized enumeration is [[],[3],[2],[2,3],[1],[1,3],[1,2],[1,2,3]]. Other orderings describe the same power set, but the practice convention fixes serialization.

What a Strong Answer Covers Guidance

Use choose-or-skip recursion or an equivalent enumeration, copy each completed subset, and explain O(n*2^n) output-sensitive time with O(n) working space excluding output.

Follow-up Questions Guidance

  • Why must the current subset be copied when adding it to the result?
  • What changes if the input contains duplicate values?