Data Structures & AlgorithmsModerateProduct-company MCQ pattern

What is the length of the shortest contiguous subarray of [1, 4, 4, 2, 3, 1, 5] whose sum is at least 9?

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

Correct answer: D. 3

No two adjacent elements reach 9 (the largest pair sum is 4 + 4 = 8, then 6 for 1 + 5), while 1 + 4 + 4 = 9 and 3 + 1 + 5 = 9 give length 3. Picking 4 and 5 for length 2 ignores contiguity.

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

Exams that ask this topic