Data Structures & AlgorithmsVery hard
Among pairs with A[i] ≠ A[j] and A[i] XOR A[j] = 0, how many exist?
- A. All pairs with odd values.
- B. None, because XOR is zero exactly when the two values are equal.
- C. Every pair of distinct values.
- D. Exactly one pair.
Correct answer: B. None, because XOR is zero exactly when the two values are equal.
XOR of two values is zero exactly when they are identical bit by bit, i.e. equal. So no pair of distinct values has XOR zero.
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
- Why can the number of distinct OR values over all subarrays of an array be small even for long arrays?
- In the array [2, 5, 5, 3, 5, 2] the maximum of a subarray is taken. How many contiguous subarrays have their maximum value occurring…
- What is the sum of the minimum over all contiguous subarrays of [3, 1, 2, 4] that have length at least 2?
- In a grid, 2 marks a rotten orange, 1 a fresh one and 0 an empty cell. Each minute every fresh orange adjacent (4 directions) to a rotten…
- The 0/1 grid [[1,1,0],[0,1,0],[1,0,1]] is given. Two 1-cells belong to the same island if they are adjacent horizontally or vertically…
- Two numbers are stored as linked lists of digits, least significant digit first: 9 -> 9 -> 9 and 1. Their sum is added digit by digit with…