Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS
How many index pairs i < j in [1, 2, 3, 4, 7, 8] have a[i] XOR a[j] equal to a power of two (1, 2, 4, 8, ...)?
- A. 4
- B. 2
- C. 9
- D. 3
Correct answer: D. 3
A value is a power of two exactly when x AND (x - 1) is zero and x is nonzero. Checking pairs with a zero AND (the last option) answers a different question.
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
- How many positive divisors does the product 4 6 9 have?
- Which minimum number of intervals from [(0,2),(1,4),(3,6),(5,9),(7,10)] are needed to cover the segment [0, 10] completely (the union must…
- What is the length of the longest contiguous subarray of [2, 4, 1, 3, 6, 7, 8, 5, 9] containing at most two odd numbers?
- For windows of size 2 over [4, 2, 12, 11, 5] (using 5 in place of -5), what is the largest window minimum?
- For "abcdab", list the five length-2 substrings and hash each as (ord(first) + ord(second)) mod 11. How many index pairs i < j have equal…
- Arrivals at times 1, 2, 3, 5 and departures at 2, 4, 5, 6 (each arrival pairs with a departure; a train leaving at time t frees its…