Login

Striver SDE Sheet Problems

Problem title

Difficulty

Avg time to solve

Divide Two Integers

Easy

10 mins

Flatten Binary Tree to Linked List

Moderate

25 mins

Find Duplicate in Array

Easy

15 mins

BST Iterator

Moderate

20 mins

Maximum Product Subarray

Moderate

25 mins

Next Smaller Element

Moderate

25 mins

Delete Node In A Linked List

Easy

15 mins

Find MSB In O(1)

Easy

10 mins

Clone Graph

Moderate

25 mins

Remove Duplicates from Sorted Array

Easy

15 mins

Problem

Submissions

2

Avg. time to solve

10 min

Success Rate

90%

Problem Statement

```
If N = 14, then the nearest integer that is less than or equal to 14 and is a power of two is 8(2^3). So, the answer is 8.
```

```
Can you solve this in constant time and space complexity?
```

```
The first line contains an integer 'T' which denotes the number of test cases. Then, the 'T' test cases area as follow.
The first and only line of each test case contains a single integer 'N'.
```

```
For each test case, print the nearest integer that is less than or equal to 'N' and also is a power of 2.
Output for each test case will be printed in a separate line.
```

```
You do not need to print anything. It has already been taken care of. Just implement the given function.
```

```
1 <= T <= 2 * 10^3
1 <= N <= 10^9
Time Limit: 1 second
```

```
2
4
22
```

```
4
16
```

```
For the first test case, 4 itself is a power of two.
For the second test case, the nearest integer that is less than or equal to 22 and also is a power of two is 16.
```

```
2
1
63
```

```
1
32
```

```
For the first test case, 1 itself is a power of two.
For the second test case, the nearest integer that is less than or equal to 63 and also is a power of two is 32.
```

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