Data Structures & AlgorithmsHardCodeforces Div 2 C · ICPC regional
Array [1, 2, 4, 1, 3, 4]. How many contiguous subarrays have a bitwise OR of exactly 7?
- A. 13
- B. 10
- C. 11
- D. 3
Correct answer: C. 11
The OR of a subarray grows as the subarray extends, so for each start index the OR takes only a few distinct values. Counting subarrays whose element sum is 7 is a different condition.
More Coding Interview Problems questions
- Set A = {1, 2, 4, 7} and set B = {3, 5, 6, 8}. Choose two different elements from A and two different elements from B. How many choices…
- Half-open intervals [0,2), [1,3), [2,4), [3,5), [4,6). What is the minimum number of intervals to remove so the remaining intervals are…
- Array a = [2, 3, 5, 1, 4, 5, 2, 3]. How many contiguous subarrays have an even length and a sum divisible by 5?
- In the binary string "1101001100", find the length of the longest substring that has equally many 0s and 1s and whose length is a multiple…
- Values [1, 9, 4, 12, 7, 15, 3]. How many unordered pairs of distinct positions have an absolute difference of at least 5?
- How many subsets of {1, 2, ..., 12} have a sum of exactly 20?