Data Structures & AlgorithmsHardGATE CS · TCS NQT · Product Company SDE

Using the sliding window technique, what is the maximum sum of any 8 consecutive elements in [24, 30, 4, 27, 25, 2, 13, 22, 26, 1]?

  1. A. 154
  2. B. 148
  3. C. 149
  4. D. 125

Correct answer: C. 149

Slide a window of size 8, adding the new element and dropping the oldest one in O(1) per step; the best window sum is 149.

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

Exams that ask this topic