Data Structures & AlgorithmsHardAmazon OA · Arrays

How many contiguous subarrays of [3, 4, 7, 2, -3, 1, 4, 2] have a sum of exactly 7?

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

Correct answer: C. 4

With prefix sums and a hash map the matching subarrays are [3,4], [7], [7,2,-3,1] and [1,4,2], so 4.

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

Exams that ask this topic