Data Structures & AlgorithmsHard
How many contiguous subarrays of 2 3 5 4 1 7 6 have a PRIME sum and an EVEN length?
- A. 5
- B. 10
- C. 6
- D. 4
Correct answer: A. 5
The prime test is applied to the sum and the even-length test to the block size; both must hold together. Dropping the length rule, flipping it, or swapping the prime test for parity each change 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 contiguous subarrays of length exactly 2 in 2 6 3 5 8 1 4 7 have a sum that is a multiple of 4 OR a product that is a multiple of…
- How many ways can three DIFFERENT sticks of lengths 2 3 4 5 6 7 (chosen by position) form a non-degenerate triangle? A triangle needs the…
- How many index quadruples i < j < k < l in 1 -1 2 -2 3 -3 have A[i] + A[j] + A[k] + A[l] = 0?
- How many index pairs i < j in 4 9 5 3 6 6 10 satisfy |A[i] − A[j]| = 1?
- How many contiguous windows of length exactly 3 in 4 1 7 3 9 5 2 have their MIDDLE element equal to the median of the window?
- How many contiguous windows of length exactly 4 in 6 2 5 9 4 7 3 satisfy (maximum − minimum) ≤ 3?