Data Structures & AlgorithmsHardCAT · Codeforces Div2 B
How many contiguous subarrays of [1, 3, 2, 6, 4, 2] have a sum divisible by their length?
- A. 15
- B. 16
- C. 21
- D. 6
Correct answer: A. 15
Test each of the 21 subarrays: 15 have a sum divisible by their length (all 6 single elements included). Checking divisibility by the first element instead gives 16, 21 counts every subarray and 6 counts only the single elements.
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
- Evaluate the integer expression 2 - 3 4 + 10 / 3 using standard precedence and integer division that truncates toward zero. What is the…
- What is the length of the longest run of consecutive integers (in any order) present in the array [9, 1, 4, 7, 3, -1, 0, 5, 8, -1, 6]?
- How many index pairs i < j in the array [1, 5, 3, 4, 2, 7, 9] have absolute difference exactly 2?
- In the array [1, 5, 5, 5, 5, 5, 5, 5, 5, 9], how many distinct value pairs {x, y} with x <= y satisfy x + y = 10, where x and y both occur…
- What is the length of the longest substring of aabccbb that can be made into a string of one repeated letter by replacing at most 2…
- How many substrings of abcabc contain all of the three letters a, b and c at least once?