Diwali Offer!Flat 20% OFF
Enroll Now
PrakalpanaLive online tech training

96. Subsets

MediumDay 28 of 60Recursion & Backtracking

Given an array nums of distinct integers, return every possible subset (the power set), including the empty set and the full array. The answer must not contain the same subset twice. You may return the subsets in any order.

Example 1
Input: nums = [1,2,3]
Output: [[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]
Example 2
Input: nums = [0]
Output: [[],[0]]
Constraints
  • 1 <= nums.length <= 10
  • -10 <= nums[i] <= 10
  • All values are distinct
Hints
Frequently asked at: Meta, Amazon, Google, Bloomberg
Ctrl + Enter runs the examples

Not sure what to learn next?

A 1-on-1 session with an industry mentor and a roadmap built for you. How it works

  1. 1Discuss your goals
  2. 2Get a personal plan
  3. 3Start learning
Book for β‚Ή200/ 30 min