Data Structures & AlgorithmsModerateCodeforces Div 2 C · ICPC regional
How many integers x with 1 <= x <= 200 have an odd number of 1-bits in their binary representation?
- A. 101
- B. 99
- C. 100
- D. 128
Correct answer: A. 101
Brute force over 1..200 finds 101 numbers with an odd popcount (the 'evil/odious' split is not exactly half here). Counting even popcounts gives 99, stopping at 199 or assuming an exact half gives 100, and 128 is half of 0..255.
More Coding Interview Problems questions
- Meetings (closed-open as half-open intervals) are [1,4), [1,4), [2,6), [5,8), [3,9), [7,10). A room can be reused the moment a meeting…
- Closed integer intervals [1,3], [2,5], [4,7], [6,9], [8,10], [5,6] are available. What is the minimum number needed so that every integer…
- Array [3, 1, 2, 5, 0, 4, 2]. How many contiguous subarrays have a sum equal to twice their length?
- Array [1, 3, 5, 4, 2, 6, 8, 7, 9]. What is the length of the shortest contiguous segment that, once sorted, makes the whole array sorted?
- How many permutations of (0, 1, 2, 3) have exactly one position i with p[i] = i?
- Arrays A = [2, 5, 3, 7] and B = [4, 6, 1, 9]. How many pairs (x from A, y from B) satisfy 10 <= x y <= 40?