Data Structures & AlgorithmsVery hard
Why does a pair (i<j) with A[i] AND A[j] = 0 require disjoint sets of set bits?
- A. AND keeps only bits set in both operands, so zero means no bit is set in both, i.e. the bit sets are disjoint.
- B. AND is zero whenever one operand is zero, so the bits do not matter.
- C. AND is zero exactly when the two numbers are equal.
- D. AND is zero for every pair of odd numbers.
Correct answer: A. AND keeps only bits set in both operands, so zero means no bit is set in both, i.e. the bit sets are disjoint.
A bit survives the AND only if both operands have it, so a zero AND means no common set bit. The disjoint-bit condition is the defining feature of such pairs.
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
- Among pairs with A[i] ≠ A[j] and A[i] XOR A[j] = 0, how many exist?
- 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…