Data Structures & AlgorithmsHardProduct Company SDE · Infosys OA

Problem: In the array [3, 8, 1, 9, 4, 7, 2, 6, 5], what is the length of the longest subarray whose sum is exactly 20?

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

Correct answer: D. 4

Brute force over all subarrays is the reference. Keep the longest window whose sum is exactly 20; the condition is exact equality, not at most 20.

More Coding Interview Problems questions

Exams that ask this topic