Data Structures & AlgorithmsHard
How many contiguous subarrays of 1 3 4 7 9 6 11 of length at least 2 contain EXACTLY one even value?
- A. 15
- B. 19
- C. 4
- D. 13
Correct answer: D. 13
Count evens in each block and require exactly one; the length-at-least-two rule removes the singleton even block. Allowing any count of evens, or counting odd singletons instead, gives a different total.
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 contiguous subarrays of 2 5 1 2 4 7 have length at least 2, contain pairwise DISTINCT values, and have an ODD sum?
- How many index pairs i < j in 1 2 3 4 6 8 satisfy A[i]·A[j] ≥ 2·(A[i] + A[j])?
- Why is a sum of XORs over subarrays NOT equal to the sum of the subarray sums?
- When counting subarrays with sum divisible by m, why does the prefix-remainder method count pairs of equal remainders?
- To count ordered pairs (i, j), i ≠ j, with A[i] + A[j] ≡ 0 (mod 5), which correction turns an unordered-pair count into the ordered one?
- When counting subarrays, why do two blocks with identical values but different positions count as two different subarrays?