Data Structures & AlgorithmsHardProduct company OA · Amazon/Microsoft-style OA
Array a = [3, 4, 7, 1, 6, 2, 5, 8]. How many contiguous subarrays have a sum that is divisible by 7?
- A. 14
- B. 11
- C. 10
- D. 9
Correct answer: B. 11
The number of subarrays with sum divisible by 7 equals the sum over residue classes of C(count, 2) of the prefix residues, with the empty prefix included. Missing the empty prefix or using the residue-1 class changes the count.
More Coding Interview Problems questions
- A 2 x 7 board is to be covered by 1 x 2 dominoes (each may be placed horizontally or vertically). How many tilings are there? Use the…
- Arrays A = [2, 3, 5, 7, 4] and B = [6, 10, 1, 3, 8]. How many pairs (x in A, y in B) satisfy x y = 24?
- Weighted intervals (start, end, value): (0,5,4), (3,9,6), (6,10,3), (9,12,5). Choose two intervals that do not overlap (touching at an…
- Array a = [-2, 5, -1, 4, -3, 6]. How many contiguous subarrays have a sum strictly between 0 and 10?
- Sorted array [2, 3, 7, 9, 12, 15, 18]. How many index pairs i < j have a difference srt[j] - srt[i] in the range (3, 8], i.e. greater than…
- How many integers x with 1 <= x <= 30 have a binary representation with no two adjacent 1-bits?