Data Structures & AlgorithmsModerateTCS NQT · CAT
Problem: How many integers n with 0 ≤ n ≤ 255 have exactly four 1-bits in their binary representation?
- A. 56
- B. 256
- C. 16
- D. 70
Correct answer: D. 70
Choose which 4 of the 8 bit positions are 1: C(8,4) = 70. C(8,3) = 56 picks three bits, 256 counts every byte, and 2⁴ = 16 confuses the count with a value.
More Coding Interview Problems questions
- Problem: What is the largest power of 2 that is less than or equal to 1000?
- Problem: Find the smallest positive integer x such that floor(x/2) + x is at least 50.
- Problem: A set of jobs has deadlines and profits: (deadline 1, profit 20), (deadline 2, profit 40), (deadline 2, profit 30), (deadline 3…
- Problem: The insertion sort is applied to [3, 1, 2]. Count the total number of element moves (each shift of an element one place to the…
- Problem: Heap-indexed binary tree with 10 nodes (node i has children 2i and 2i+1 when ≤ 10). How many nodes lie at depth 2 (root at depth…
- Problem: In the sorted array [−3, −1, 0, 1, 2, 3], how many pairs of distinct positions (i < j) have a sum of exactly 0?