Search⌘ K
AI Features

Subsets / Powerset

Explore how to find all subsets of a given input using bitwise left shift operations. Understand the iterative approach to generate power sets, enabling efficient solutions for common coding interview problems.

Introduction

In this lesson, we discuss the subsets of a given input. This is one of the most popular questions asked in coding interviews.

Companies that have asked this in their coding interview are Apple, Microsoft, Amazon, Facebook, and many more.

Problem Statement

We need to write a program that finds all possible subsets ( the power set) of a given input. The solution set must not contain duplicate subsets.

Input: [1, 2, 3]

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

Output: [[], [100]]

Explanation: The subsets of any given input are equal to its power set.

if, input n = 3, then, powerset => 2n2^{n} = 232^{3} ...