Math Fundamentals18 sections · 814 units
Open in Course

Problem - Subsets

LeetCode 78

Given an array of distinct integers, return all possible subsets. The solution set must not contain duplicate subsets.

For example, given [1,2,3][1, 2, 3], return [[],[1],[2],[3],[1,2],[1,3],[2,3],[1,2,3]][[], [1], [2], [3], [1,2], [1,3], [2,3], [1,2,3]].

You can solve this with backtracking, but there's a direct bit manipulation approach. Think about representing each subset as a bitmask.