Login

Striver SDE Sheet Problems

Problem title

Difficulty

Avg time to solve

Reverse Pairs

Hard

50 mins

Ninja And Ladoos

Hard

10 mins

Detect the first node of the loop

Moderate

10 mins

Count Set Bits

Hard

15 mins

K-th Permutation Sequence

Moderate

15 mins

Ninja at the Gym

Moderate

10 mins

Calculate square of a number

Easy

15 mins

Combination Sum II

Moderate

30 mins

Find Pattern in String

Easy

10 mins

Z Algorithm

Hard

15 mins

Problem

Submissions

3

Avg. time to solve

15 min

Success Rate

85%

Problem Statement

```
Do not print anything, just return the number of set bits in the binary representation of all integers between 1 and ‘N’.
```

```
The first line of input contains an integer ‘T’ denoting the number of test cases to run.
Then the next ‘T’ lines represent the ‘T’ test cases.
The first line of each test case contains a single integer ‘N’.
```

```
For each test case, return an integer that is equal to the count of set bits in all integers from 1 to n modulo 1e9+7.
Output for each test case will be printed in a new line.
```

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

```
1 <= T <= 100
1 <= N <= 10^9
Time limit: 1 second
```

```
2
5
3
```

```
7
4
```

```
In the first test case,
DECIMAL BINARY SET BIT COUNT
1 01 1
2 10 1
3 11 2
4 100 1
5 101 2
1 + 1 + 2 + 1 + 2 = 7
Answer = 7 % 1000000007 = 7
In the second test case,
DECIMAL BINARY SET BIT COUNT
1 01 1
2 10 1
3 11 2
1 + 1 + 2 = 4
Answer = 4 % 1000000007 = 4
```

```
2
6
10
```

```
9
17
```

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