Login

Striver SDE Sheet Problems

Problem title

Difficulty

Avg time to solve

Nth Root Of M

Easy

10 mins

Cycle Detection In Undirected Graph

Moderate

--

Power Set

Easy

15 mins

Binary Tree Zigzag Traversal

Easy

15 mins

Maximum meetings

Easy

10 mins

Detect Cycle In A Directed Graph

Moderate

30 mins

Largest rectangle in a histogram

Hard

25 mins

Connect Nodes at Same Level

Moderate

30 mins

Strongly Connected Components (Tarjan’s Algorithm)

Hard

15 mins

Median of two sorted arrays

Hard

25 mins

Problem

Submissions

6

Avg. time to solve

15 min

Success Rate

85%

Problem Statement

```
If we are given an array ARR=[1,2,3] then the power set P(ARR) of the set ARR is: [ [], [1], [2], [1,2], [3], [1,3], [2,3], [1,2,3] ]
```

```
For every subset 'X' present in power set P(ARR) of set ARR, X must be sorted i.e. in the example above:
P1(ARR) = [ [], [1], [2], [1,2], [3], [1,3], [2,3], [1,2,3] ]
P2(ARR) = [ [], [1], [1,2,3], [2], [1,2], [3], [1,3], [2,3] ]
P3(ARR) = [ [], [1], [2], [1,2], [3], [1,3], [2,3], [2,3,1] ]
P1(ARR) and P2(ARR) will be considered correct power sets but P3(ARR) will not be considered correct because there the last subset [2, 3, 1] is not sorted.
```

```
The first line contains a number 'N' denoting the size of the array.
The second line contains 'N' space-separated distinct integer denoting the elements of the array.
```

```
For each given 'N' print 2^N separate lines each denoting a subset.
For each subset, print its element separated by space.
```

```
You don’t have to print anything, it has already been taken care of. Just implement the given function.
```

```
1 <= N <= 15
1 <= ARR[i] <= 50
Time limit : 1 second
```

```
3
1 2 3
```

```
1
2
3
1 2
1 3
2 3
1 2 3
```

```
The power set P(ARR) of set ARR = [1, 2, 3] is [ [], [1], [2], [1, 2], [3], [1, 3], [2, 3], [1, 2, 3] ].
```

```
3
5 7 8
```

```
8
7
5
5 8
5 7
5 7 8
```

Console

Sample Test Case

Custom Test Case

Download Test Cases

Test Case 1

Test Case 2

Test Case 3

Saving Code...

Full Screen Mode

Change Language

Change Theme

Solution submission not allowed

Save Code

Reset Code