Print all subset

TopicDifficultyCompanies
Backtracking
MEDIUM
Amazon
Microsoft
Facebook

Given a set of distinct integers Sreturn all possible subsets.

Problem Note

  • The solution set must not contain duplicate subsets.
  • The set is not necessarily sorted.
  • You can return all subsets in any order(not necessarily sorted).
  • The total number of subsets of a given set of size n is equal to 2^n.

Example 1

Input: S[] = [2,3,4]
Output:
[
[],
[2],
[2,3],
[2,3,4],
[2,4],
[3],
[3,4],
[4]
]
Explanation: All the subsets of the given set S is printed.

Code Editor

Practice and Learn

Best way to learn is through solving real problems. Practice this problem in this code editor.