Data Structures & AlgorithmsVery hardCodeforces Div2 D · TCS NQT

Choose two NON-OVERLAPPING contiguous windows of [5, -2, 8, 1, -3, 6, 2, 4]: one of length exactly 2 and one of length exactly 3. What is the maximum total of their sums?

  1. A. 17
  2. B. 23
  3. C. 22
  4. D. 21

Correct answer: D. 21

Compute window sums of both lengths, then for every cut position combine the best window on one side with the best window of the other length on the other side using prefix and suffix maxima. Taking the two best windows independently can make them overlap.

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

Exams that ask this topic