Home
Log in
DescriptionSubmissionsSolution
DescriptionSubmissionsSolution
Loading...

Log in to run or submit

nums =

Codey

Practise coding problems, test your solutions and track your progress.

Explore

  • Problems
  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

© 2026 Codey. Personal learning project.

Solution
Updated: 2026-02-23

Idea

Sort so duplicates are adjacent, then skip duplicates at the same recursion depth.

Approach

Backtrack by start index i. At each level, iterate j from i..end:

  • If j > i and nums[j] == nums[j-1], skip (avoids duplicate subsets).

Why it works

Sorting groups duplicates; skipping equal values at the same depth prevents generating the same subset more than once.

Code
Loading...
Complexity
Time: O(n*2^n)
Space: O(n)
Solution
Updated: 2026-02-23

Idea

Sort so duplicates are adjacent, then skip duplicates at the same recursion depth.

Approach

Backtrack by start index i. At each level, iterate j from i..end:

  • If j > i and nums[j] == nums[j-1], skip (avoids duplicate subsets).

Why it works

Sorting groups duplicates; skipping equal values at the same depth prevents generating the same subset more than once.

Code
Loading...
Complexity
Time: O(n*2^n)
Space: O(n)