Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS
What is the length of the longest contiguous subarray of [3, 1, 4, 1, 5, 9, 2, 6] whose sum is divisible by 3?
- A. 8
- B. 31
- C. 3
- D. 6
Correct answer: D. 6
Store the first index of each prefix residue mod 3; the longest gap gives [4, 1, 5, 9, 2, 6] with sum 27, length 6. The whole array (8) sums to 31, which is not divisible by 3; 31 is that sum, and 3 is a shorter valid window.
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 index pairs i < j of [2, 8, 3, 12, 6, 18] have a product that is a perfect square?
- Meetings are [0,30), [5,10), [15,20), [35,45), [40,50). A meeting ending at time t and another starting at t can share a room. What is the…
- What is the sum of the minimum over every window of size 2 in [5, 2, 8, 1, 9]?
- How many ordered pairs (a, b) with 1 <= a, b <= 10 satisfy a^2 + b^2 <= 50?
- How many integers from 1 to 64 inclusive are either a power of two or have exactly two 1-bits in binary?
- What is the length of the longest palindromic subsequence of "bbbab"?