...

/

Find All Subsets of a Set

Find All Subsets of a Set

Find all subsets of a given set of integers.

Statement

Given a set of integers, find all possible subsets within the set.

Example

For the given set of integers:

g array 2 5 7

All possible subsets are:

g array 2 5 2,5 7 2,7 5,7 2,5,7

Sample input

[2, 5, 7]

Expected output

[[], [2], [5], [2, 5], [7], [2, 7], [5, 7], [2, 5, 7]]

Try it yourself

#include <iostream>
#include <vector>
#include <unordered_set>
#include <string>
using namespace std;
void FindAllSubsets(vector<int>& v, vector<unordered_set<int>>& sets) {
//TODO: Write - Your - Code
}

Solution

There are several ways to solve this problem, but we will discuss the one that is neat and easier to understand. We know that for a set of nn ...

Access this course and 1400+ top-rated courses and projects.