Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA

How many contiguous subarrays of [2, 4, 2, 1, 3] have a sum exactly equal to twice their maximum?

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

Correct answer: C. 2

Check each subarray: its sum must equal 2 * max. Singletons never qualify, so only subarrays of length at least 2 are candidates.

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

Exams that ask this topic