Data Structures & AlgorithmsModerateCodeforces Div2 B-D · ICPC regional

From [4, -2, 7, 1, -5, 3, 8, 2], choose a window of 4 consecutive elements, then remove exactly one element from that window. What is the maximum possible sum of the remaining elements?

  1. A. 13
  2. B. 14
  3. C. 19
  4. D. 10

Correct answer: A. 13

Remove the most negative element of each window, or equivalently the smallest one, and take the best window. Removing the largest value is the opposite choice and gives a smaller total.

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

Exams that ask this topic