Data Structures & AlgorithmsHard

Choose two NON-OVERLAPPING contiguous windows of length exactly 2 from 4 -2 7 1 -5 6 3 -1. What is the largest possible total sum of their elements?

  1. A. 18
  2. B. 9
  3. C. 13
  4. D. 17

Correct answer: D. 17

Two windows must not share an element, so for each second window the first must end before it begins. Doubling the best window, or allowing the windows to overlap, measures a different configuration.

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

Exams that ask this topic