Data Structures & AlgorithmsModerateCAT · TCS NQT
Problem: How many integers from 1 to 50 have exactly two 1-bits in their binary representation?
- A. 10
- B. 15
- C. 6
- D. 21
Correct answer: B. 15
Numbers with two 1-bits below 64 number C(6, 2) = 15, and the largest, 48 = 110000, is still ≤ 50, so all 15 count. Using only 5-bit numbers gives C(5, 2) = 10, counting exactly one 1-bit gives 6, and C(7, 2) = 21 covers up to 127.
More Coding Interview Problems questions
- Problem: What is the sum of the decimal digits of 9⁹?
- Problem: Arrange the numbers 3, 30, 34, 5, 9 so that their decimal concatenation is the largest possible number. What is that largest…
- Problem: Minimum number of jumps to reach the last index of [2, 3, 1, 1, 4] when from index i you may jump up to a[i] steps forward. What…
- Problem: Find the k-th largest element of [3, 2, 1, 5, 6, 4] for k = 2 (1-indexed among values, with duplicates counted separately).
- Problem: The intervals [1,3], [2,4], [3,6], [7,8], [5,9], [8,10] are given. What is the minimum number of intervals to remove so that the…
- Problem: Find the number of unique triplets (as value sets) that sum to zero in [−1, 0, 1, 2, −1, −4].