Data Structures & AlgorithmsHard
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?
- A. 0
- B. 9
- C. 2
- D. 3
Correct answer: D. 3
The OR of two values is at least each of them, so the test compares the bitwise union against the maximum directly. Using AND, a ≥ bound, or XOR measures different relations.
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
- 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)?
- How many contiguous subarrays of length exactly 2 in 2 4 7 9 1 3 6 8 consist of two values with the SAME parity?
- How many index triples i < j < k in 1 2 2 3 4 6 8 satisfy A[i] · A[j] = A[k]?
- How many contiguous subarrays of 3 3 2 4 1 2 have a sum EXACTLY equal to (their length) × (their minimum)?