Data Structures & AlgorithmsModerateTCS NQT · Codeforces Div2 B

What is the largest sum of any contiguous window of exactly 4 elements of [2, 7, 1, 8, 2, 8, 1, 8, 2, 8]?

  1. A. 19
  2. B. 18
  3. C. 23
  4. D. 11

Correct answer: A. 19

A fixed-size sliding window updates the sum by adding the entering element and removing the leaving one, giving O(n). Taking the four largest values overall ignores that they must be contiguous.

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

Exams that ask this topic