Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div2 C

Problem: The longest subarray with sum divisible by 4 in [5, 3, 7, 2, 2, 6, 1, 1]: what is its length?

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

Correct answer: C. 5

Equal prefix residues mod 4 bracket a subarray whose sum is divisible by 4. Storing the latest index instead of the first gives shorter subarrays.

More Coding Interview Problems questions

Exams that ask this topic