Data Structures & AlgorithmsModerate
How many DISTINCT values arise as the bitwise OR of a non-empty contiguous subarray of 1 2 4 2?
- A. 10
- B. 3
- C. 6
- D. 7
Correct answer: C. 6
OR values stay within a small set because each new element can only add bits; collect the set of OR values over all blocks. Counting blocks, counting blocks of length at least 2, or counting distinct inputs measures other things.
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 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)?
- 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]?