Data Structures & AlgorithmsHard

What is the maximum sum of a contiguous subarray of 4 9 1 6 3 2 8 5 that has length at least 2 and whose sum is divisible by 5?

  1. A. 38
  2. B. 26
  3. C. 24
  4. D. 25

Correct answer: D. 25

Filter the subarrays by length and by divisibility, then take the maximum sum among survivors. Allowing singletons, dropping the divisibility test, or taking the best non-divisible block each change the answer.

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

Exams that ask this topic