Data Structures & AlgorithmsHardGATE CS · TCS NQT
How many contiguous subarrays of [3, 4, 1, 2, 5, 6] have a sum divisible by 5?
- A. 5
- B. 3
- C. 4
- D. 6
Correct answer: C. 4
Two subarrays with equal prefix-sum residues mod 5 differ by a subarray whose sum is divisible by 5, so count pairs of equal residues among the prefix sums (including the empty prefix).
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 pairs i < j with 1 <= i, j <= 12 have i times j divisible by 12?
- What is the value of the sum of floor(20 / i) for i = 1 to 20?
- A bubble sort performs left-to-right passes, swapping adjacent elements that are out of order, and stops after the first pass in which no…
- Six people stand in a circle numbered 1 to 6. Starting from person 1, every 4th person (counting the start as 1) is removed until one…
- How many contiguous subarrays of [1, 3, 2, 4, 6, 5] have (maximum minus minimum) at most 2?
- How many non-empty contiguous subarrays of [2, -1, -1, 3, -2, 1, 1, -2, 0] have a sum of exactly 0?