Power Set

Recursion Implementation Problems Easy

Given an array of integers nums of unique elements. Return all possible subsets (power set) of the array.


Do not include the duplicates in the answer.

Examples:

Input : nums = [1, 2, 3]

Output : [ [ ] , [1] , [2] , [1, 2] , [3] , [1, 3] , [2, 3] , [1, 2 ,3] ]

Input : nums = [1, 2]

Output : [ [ ] , [1] , [2] , [1,2] ]

Input : nums = [0]

Constraints

  • 1 <= nums.length <= 10
  • -10 <= nums[i] <= 10

Hints

  • Use recursion to build subsets by deciding for each element whether to include it in the current subset.
  • "At each recursive step: Add the current subset to the result. Recursively add subsets including the next element."

Company Tags

Wayfair Dropbox Red Hat Swiggy Bain & Company Roche Zynga Nutanix Morgan Stanley Freshworks Visa MongoDB Seagate Technology Bloomberg Bungie Optum Boston Consulting Group Micron Technology Splunk HCL Technologies Activision Blizzard DoorDash Philips Healthcare Riot Games JPMorgan Chase TCS Cognizant Accenture Infosys Capgemini Wipro