Data Structures & AlgorithmsModerate
How many index pairs i < j in 1 2 3 4 5 6 satisfy A[i] AND A[j] = 0 (bitwise AND)?
- A. 6
- B. 0
- C. 7
- D. 5
Correct answer: A. 6
Two numbers have AND zero when their set bits are disjoint, which is a bit-level test for each pair. OR being zero, XOR being zero, and the AND equalling one operand are different conditions.
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
- What is the sum, over all non-empty contiguous subarrays of 1 3 5, of the bitwise OR of each subarray?
- How many DISTINCT values arise as the bitwise OR of a non-empty contiguous subarray of 1 2 4 2?
- How many index pairs i < j in 3 5 6 1 4 2 satisfy A[i] OR A[j] = 6, the maximum value of the array?
- Consider the windows of length 3 of 1 2 3 1 2 4 1 2 starting at positions i and i+1. How many i satisfy sum(window i) = sum(window i+1)?
- How many contiguous subarrays of 1 3 2 5 4 6 1 2 of length at least 3 have exactly one interior strict local maximum (a position strictly…
- How many index pairs i < j in 2 5 3 9 4 7 6 satisfy A[i] < A[j] AND (A[j] − A[i]) divides (j − i)?