Data Structures & AlgorithmsHardTCS NQT Digital · ICPC regional
Problem: Let f(n) = number of 1-bits in n. Compute Σ f(n) for n from 0 to 63 inclusive.
- A. 192
- B. 384
- C. 160
- D. 224
Correct answer: A. 192
Each of the 6 bit positions is set in exactly 32 of the 64 numbers 0..63, so the total is 6 × 32 = 192. Forgetting the 'half' gives 6 × 64 = 384, using 5 bits gives 160, and assuming 7 bits gives 224.
More Coding Interview Problems questions
- Problem: Starting at (0,0), the robot moves in the string "NNEESSWWNE" with N = up, E = right, S = down, W = left. Count the number of…
- Problem: The sequence a1 = 2, and each next term is a(n+1) = (a(n) × 3 + 1) mod 11. What is a(20)?
- Problem: A bag holds coins of values 1, 4 and 9. You must pay exactly 30 using as few coins as possible. What is the minimum number of…
- Problem: The 0/1 matrix [[1,0,1],[1,1,0],[0,1,1]] is considered. A 'plus' is a centre cell with value 1 whose four neighbours (up, down…
- Problem: Two heaps are maintained over the stream 5, 15, 1, 3, 8, 7, 9, 10, 6, 11 to report the median after each element (lower median…
- Problem: The string "abcabcbb" is scanned and for each position the length of the longest run of distinct characters starting at that…