Data Structures & AlgorithmsHardGATE CS

For the array [7, 2, 4, 9, 3, 5, 1, 8, 6, 2, 10, 4, 3, 9] and window size k = 4, compute (maximum - minimum) for every window of k consecutive elements. What is the sum of these differences over all windows?

  1. A. 84
  2. B. 100
  3. C. 80
  4. D. 20

Correct answer: C. 80

There are 11 windows. The sum of maxima is 100 and the sum of minima is 20, so the sum of (max - min) is 80.

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

Exams that ask this topic