Data Structures & AlgorithmsModerate
How many contiguous subarrays of [3, 1, 4, 1, 5, 9, 2, 6] have a sum that is divisible by their own maximum element?
- A. 33
- B. 11
- C. 3
- D. 4
Correct answer: B. 11
The divisibility test uses the subarray's own maximum, found by scanning the block; dividing by the minimum or by the length tests different quantities. Excluding single elements drops the trivially divisible blocks, which must be counted.
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
- For the array [4, -1, 2, -3, 5, -6, 3], what is the maximum value of (sum of a non-empty contiguous subarray) − 2 × (its length)?
- How many index pairs i < j in [5, 1, 9, 4, 8, 3, 7] satisfy |A[i] − A[j]| ≤ 3?
- How many contiguous subarrays of [1, 0, 1, 1, 0, 0, 1, 0, 1] contain EXACTLY one 0?
- How many contiguous subarrays of [1, 2, 3, 1, 2, 1, 3, 3] contain the values 1, 2 and 3 each at least once?
- What is the minimum number of elements you must DELETE from [5, 1, 9, 4, 8, 3, 7] (the remaining elements keep their order but need not be…
- How many index pairs i < j in [2, 8, 3, 18, 4, 12, 5] have a product A[i]·A[j] that is a perfect square?