Data Structures & AlgorithmsModerateProduct-company MCQ pattern

A fixed-size sliding window of length 3 moves over [2, 1, 5, 1, 3, 2, 9, 1]. What is the largest window sum?

  1. A. 15
  2. B. 9
  3. C. 12
  4. D. 14

Correct answer: D. 14

Window sums are 8, 7, 9, 6, 14, 12 (each new sum = previous + entering element − leaving element), so the maximum is 3 + 2 + 9 = 14. 12 is the last window, 2 + 9 + 1.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic