The "Subsets" problem is a fundamental backtracking challenge. Given an array of unique integers, you need to return all possible subsets (the power set). A subset is any combination of elements from the original array, including the empty set and the array itself. For an array of size n, there are always 2^n possible subsets. The order of the subsets in the output does not matter.
This is a core question asked by almost every major tech company, including Apple, Amazon, and Google. It is the definitive test of a candidate's understanding of Backtracking and Recursion. It evaluates whether you can visualize a decision tree—where at each step you either include an element in your subset or you don't. It's a baseline requirement for roles involving algorithm development.
The problem is typically solved using Backtracking or Bit Manipulation.
Array: [1, 2]
The most common mistake is failing to "backtrack" properly—forgetting to remove an element from the current path before returning from a recursive call. Another mistake is not creating a deep copy of the subset before adding it to the result list, which results in a list of empty arrays (since the original array is eventually cleared). Candidates also sometimes struggle to explain the 2^n time complexity.
To excel in the Subsets interview pattern, draw out the recursion tree for a small example like [1, 2, 3]. Visualizing how the code "moves" through the tree will help you explain it more clearly. Also, be ready to discuss the Bit Manipulation approach as an alternative, as it demonstrates a different but equally valid mental model.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Subsets II | Medium | Solve | |
| Count Number of Maximum Bitwise-OR Subsets | Medium | Solve | |
| Maximum Length of a Concatenated String with Unique Characters | Medium | Solve | |
| Non-decreasing Subsequences | Medium | Solve | |
| Maximum Points in an Archery Competition | Medium | Solve |