Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA

From the windows of length 3 of [3, 9, 2, 8, 1, 7], remove the smallest element of the chosen window and maximise the sum that remains. What is the largest remaining sum?

  1. A. 18
  2. B. 15
  3. C. 17
  4. D. 14

Correct answer: C. 17

Within each window the best removal is its minimum, so the answer is the maximum over windows of (window sum minus window minimum). Removing the largest element is the opposite greedy and is wrong.

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

Exams that ask this topic