Data Structures & AlgorithmsVery hardProduct company OA · Amazon/Microsoft-style OA
Array a = [2, 3, 5, 1, 4, 5, 2, 3]. How many contiguous subarrays have an even length and a sum divisible by 5?
- A. 8
- B. 10
- C. 7
- D. 16
Correct answer: A. 8
Separate the length condition from the sum condition: count subarray pairs whose prefix residues mod 5 match and whose start and end positions have the same parity, using a hash map keyed by (residue, parity).
More Coding Interview Problems questions
- 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?
- How many integers x with 1 <= x <= 200 have an odd number of 1-bits in their binary representation?
- Meetings (closed-open as half-open intervals) are [1,4), [1,4), [2,6), [5,8), [3,9), [7,10). A room can be reused the moment a meeting…
- Closed integer intervals [1,3], [2,5], [4,7], [6,9], [8,10], [5,6] are available. What is the minimum number needed so that every integer…