Data Structures & AlgorithmsVery hardCodeforces Div2 B-D · ICPC regional

Choose two disjoint contiguous windows of length exactly 2 in [1, 2, 9, 4, 5, 1, 8, 3] (the windows may not share an index). What is the maximum total of their sums?

  1. A. 24
  2. B. 25
  3. C. 22
  4. D. 16

Correct answer: A. 24

A prefix maximum of window sums, updated as the second window starts after the first ends, gives the answer in linear time. Allowing the two windows to overlap inflates the total.

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

Exams that ask this topic