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

97. Subsets II

MediumDay 28 of 60Recursion & Backtracking

Given an integer array nums that may contain duplicates, return all possible subsets. The answer must not contain two subsets with the same elements (as multisets), so [1,2] and [2,1] count as the same subset. Return them in any order.

Example 1
Input: nums = [1,2,2]
Output: [[],[1],[1,2],[1,2,2],[2],[2,2]]
Example 2
Input: nums = [0]
Output: [[],[0]]
Constraints
  • 1 <= nums.length <= 10
  • -10 <= nums[i] <= 10
Hints
Frequently asked at: Amazon, Microsoft, Meta
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