Login

All Problems

Problem title

Difficulty

Avg time to solve

N-ary tree Level Order Traversal

Moderate

20 mins

Third greatest element

Easy

20 mins

Ninja's Encryption

Easy

15 mins

Minimum and Maximum Cost to buy N Candies

Hard

10 mins

Properties of MST in a Undirected Graph

Easy

15 mins

Chocolates With Magical Number

Easy

10 mins

Merge Two Binary Trees

Easy

15 mins

Number of Ones

Easy

15 mins

Uncommon Characters

Moderate

25 mins

Minimum Connection Changes

Moderate

30 mins

Problem

Submissions

2

Avg. time to solve

15 min

Success Rate

85%

Problem Statement

```
Given ‘NUM = 9’
Binary representation of ‘9 = 1001’, so there are 2 times 1's present.
Print ‘2’ as the answer.
```

```
The first line contains a single integer ‘T’ representing the number of test cases.
The only line of each test case contains a single integer ‘NUM’ representing an integer whose number of bits which are ‘1’ in the binary representation you need to print.
```

```
For each test case print the number of bits ‘1’ in binary representation.
Print the output of each test case in a separate line.
```

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

```
1 <= T <= 10000
1 <= NUM <= 10^9
Time Limit: 1sec
```

```
4
1
2
17
11
```

```
1
1
2
3
```

```
Test case 1:
1’s binary representation is 1. The number of bits 1 in binary representation is 1. Therefore the answer is 1.
Test case 2:
2’s binary representation is 10. The number of bits 1 in binary representation is 1. Therefore the answer is 1.
Test case 3:
17’s binary representation is 10001. The number of bits 1 in binary representation is 2. Therefore the answer is 2.
Test case 4:
11’s binary representation is 1011. The number of bits 1 in binary representation is 3. Therefore the answer is 3.
```

```
2
15
100
```

```
4
3
```

```
Test case 1:
15’s binary representation is 1111. The number of bits 1 in binary representation is 4. Therefore the answer is 4.
Test case 2:
100’s binary representation is 1100100. The number of bits 1 in binary representation is 3. Therefore the answer is 3.
```

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