Data Structures & AlgorithmsModerateCodeforces Div 2 C · ICPC regional
What is the minimum number of single-bit flips needed to change the 8-bit number 13 into the 8-bit number 22?
- A. 5
- B. 3
- C. 4
- D. 1
Correct answer: C. 4
Only bits where the two numbers differ need flipping, so the answer is the popcount of 13 XOR 22. Counting differences in AND or OR bits uses a different expression and gives another value.
More Coding Interview Problems questions
- Consider the eight primes 2, 3, 5, 7, 11, 13, 17, 19. How many subsets (including the empty subset, whose product is 1) have a product…
- How many 3-element subsets of {1, 2, 3, 4, 5, 6, 7, 8} have a sum divisible by 6?
- Half-open intervals [1,4), [2,6), [3,5), [5,8), [7,9), [8,10) are given. What is the largest number of them you can select so that no time…
- Meetings are closed-open intervals [1,3), [2,5), [4,6), [5,7), [6,9), [8,10) and one room can hold one meeting at a time. A meeting may…
- Sprinklers at positions p with radius r cover the closed interval [p - r, p + r] of a garden. The sprinklers are (1,2), (4,1), (7,3)…
- Jump game: array a = [2, 3, 1, 1, 4, 2, 1, 3, 1, 2]. Starting at index 0, from index i you may jump forward to any index between i+1 and…