Data Structures & AlgorithmsHardProduct company OA · Amazon/Microsoft-style OA
Split the array [7, 2, 5, 10, 8, 4, 6] into 3 non-empty contiguous parts so that the largest part sum is as small as possible. What is that minimum possible largest sum?
- A. 21
- B. 16
- C. 10
- D. 18
Correct answer: D. 18
Binary search on the answer: a cap works when a greedy left-to-right split needs at most 3 parts, and the feasibility test is monotone in the cap. Splitting by equal counts instead of equal sums gives a larger maximum.
More Coding Interview Problems questions
- Sorted arrays A = [1, 4, 6, 9] and B = [2, 3, 7, 10]. How many pairs (x from A, y from B) have 8 <= x + y <= 12?
- Array a = [1, 2, 3, 1, 2, 3, 1]. How many contiguous subarrays of length at least 2 have the sum of the elements at even offsets (0, 2, 4…
- Array [1, 2, 3, 4, 5, 6, 7, 0]. How many index pairs i < j satisfy (a[i] OR a[j]) = 7?
- Coins have values 1, 3, 9, 27, 81, ... (powers of three, unlimited supply). What is the minimum number of coins needed to pay exactly 41?
- Array [5, 1, 4, 6, 2, 8, 3, 7]. What is the length of the longest contiguous subarray whose maximum minus minimum is at most 3?
- Array a = [3, 4, 7, 1, 6, 2, 5, 8]. How many contiguous subarrays have a sum that is divisible by 7?