Data Structures & AlgorithmsHardGATE CS · ICPC regional
How many contiguous subarrays of [4, 5, 0, -2, -3, 1] have a sum divisible by 4?
- A. 7
- B. 4
- C. 6
- D. 9
Correct answer: C. 6
Count pairs of equal prefix sums modulo 4, including the empty prefix; note that Python's % gives non-negative residues, while C-style remainders can be negative and break the count.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- How many distinct values v in the array [1, 2, 2, 3, 3, 3, 4, 4, 4, 4] occur exactly v times?
- What is the length of the longest common prefix of the strings interstellar, internet, interval and intern?
- How many integers x with 1 <= x <= 100 satisfy x mod 3 = 2 and x mod 5 = 3?
- How many contiguous subarrays of [7, 1, 6, 13, 8, 2] have a sum congruent to 0 modulo 7?
- How many positive divisors of 720 are perfect squares?
- Two people in a circle of 5 are numbered 1 to 5 and eliminated by repeatedly removing every second person (starting by removing person 2)…