Subsets Problem
Subsets Problem — ExecCode Medium DSA Practice
Solve the Subsets problem on ExecCode. Free online medium DSA practice in Backtracking. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Given an integer array nums of unique elements, return all possible subsets (the power set), with no duplicate subsets, in any order. At each recursive call, record the current path first, then extend it with every remaining element in turn.
Examples
Input nums = [1, 2, 3]; Output [[], [1], [1, 2], [1, 2, 3], [1, 3], [2], [2, 3], [3]]. Input nums = [0]; Output [[], [0]]. Input nums = [1, 2]; Output [[], [1], [1, 2], [2]]
Constraints
1 <= nums.length <= 10 All integers in nums are unique.
Practice Subsets free on ExecCode. Browse DSA problems, topic map, and placement guides.