Data Structures & AlgorithmsHardProduct company OA · Amazon/Microsoft-style OA
Array [4, 7, 1, 9, 3, 6, 2, 5]. How many pairs of prefix indices (i < j) among the nine prefix sums (including the empty prefix) have a difference divisible by 10?
- A. 6
- B. 1
- C. 32
- D. 4
Correct answer: D. 4
Two prefix sums differ by a multiple of 10 exactly when they have the same remainder mod 10, so count the remainder classes and add C(c, 2) for each. The empty prefix is one of the nine prefixes and must be included.
More Coding Interview Problems questions
- How many integers x with 1 <= x <= 100 are divisible by 3 and have exactly two 1-bits in their binary representation?
- Positive array [2, 7, 1, 8, 3, 4, 6]. What is the largest possible sum of a contiguous subarray that does not exceed 15?
- Half-open intervals [1,5), [3,8), [6,10), [9,12) are given. How many integer points x are covered by at least two of these intervals?
- Half-open intervals [0,4), [3,7), [6,9), [8,12). How many unit cells [x, x+1) are covered by two or more intervals?
- Array [2, 3, 5, 10, 2, 0, 1]. How many contiguous non-empty subarrays have a sum equal to exactly twice their maximum element?
- How many pairs of integers (x, y) with 1 <= x < y <= 12 satisfy x XOR y = x + y?