Data Structures & AlgorithmsHardProduct company OA · Amazon/Microsoft-style OA

Positive array [2, 7, 1, 8, 3, 4, 6]. What is the largest possible sum of a contiguous subarray that does not exceed 15?

  1. A. 13
  2. B. 15
  3. C. 31
  4. D. 10

Correct answer: B. 15

A sliding window (all values positive) finds 7 + 8 = 15 and also 8 + 3 + 4 = 15, the cap exactly. Using < 15 gives 13, ignoring the cap gives the total 31, and growing a window only from the start gives 2 + 7 + 1 = 10.

More Coding Interview Problems questions

Exams that ask this topic