Data Structures & AlgorithmsHardGATE CS · TCS NQT

What is the length of the longest contiguous subarray of [4, 3, 2, 6, 1, 5] whose sum is at most 10?

  1. A. 3
  2. B. 4
  3. C. 5
  4. D. 7

Correct answer: A. 3

All values are positive, so a two-pointer window that shrinks while the sum exceeds 10 finds the longest valid window.

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

Exams that ask this topic