Data Structures & AlgorithmsModerateCodeforces Div 2 C · ICPC regional
How many integers x with 0 <= x <= 255 have a number of 1-bits that is divisible by 3? (Zero has zero 1-bits, which is divisible by 3.)
- A. 86
- B. 84
- C. 56
- D. 85
Correct answer: D. 85
Popcounts 0, 3 and 6 qualify: C(8,0) + C(8,3) + C(8,6) = 1 + 56 + 28 = 85. Leaving out zero gives 84, counting only exactly three 1-bits gives 56, and counting multiples of 3 (a misreading) gives 86.
More Coding Interview Problems questions
- Trains arrive at [900, 940, 950, 1100, 1500, 1800] and depart at [910, 1200, 1120, 1130, 1900, 2000] (matched train by train). A platform…
- Problem: Children stand in a line with ratings [1, 0, 2]. Each child gets at least one candy, and a child with a higher rating than a…
- Problem: Water is poured into a container of heights [1, 8, 6, 2, 5, 4, 8, 3, 7]. Choose two lines to maximise the area of water they…
- Problem: Trucks carry boxes: each truck type is (count, units per box), and at most 10 boxes fit on the truck. Maximise units per truck…
- Problem: How many contiguous subarrays of [1, 2, 3, 4, 5] have sum exactly 5? Run the code. python a = [1, 2, 3, 4, 5] print(sum(1 for i…
- Problem: What is the length of the longest zigzag subsequence (values alternate strictly up and down) of [1, 7, 4, 9, 2, 5]? Run the DP…