Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS
How many index pairs i < j in [1, 3, 5, 7, 9, 15] have a sum that is a power of two?
- A. 6
- B. 4
- C. 15
- D. 5
Correct answer: D. 5
A positive integer is a power of two when x AND (x - 1) is zero. Checking pair sums directly with that test avoids logarithms and floating point errors.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- From tasks (value, cost) = (5, 4), (6, 2), (3, 1), (7, 5) you may choose any subset whose total cost is at most 7. What is the maximum…
- How many trailing zeros does 2^7 5^4 10 have in decimal?
- What is the number of unmatched '(' characters in the string "(()())(()" after the standard left-to-right matching?
- What is the largest number of distinct characters in any contiguous window of length 4 of "abcbdabca"?
- What is the sum of all positive divisors of 36?
- How many contiguous subarrays of [2, 4, 1, 3] have a sum in the inclusive range [4, 6]?