Data Structures & AlgorithmsHard
How many contiguous subarrays of length exactly 2 in 2 4 7 9 1 3 6 8 consist of two values with the SAME parity?
- A. 2
- B. 0
- C. 6
- D. 5
Correct answer: D. 5
Parity equality is checked for each adjacent pair of positions; a length-2 window contains exactly one such pair. Comparing the opposite parity, testing equal values, or comparing positions two apart each count something else.
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 triples i < j < k in 1 2 2 3 4 6 8 satisfy A[i] · A[j] = A[k]?
- How many contiguous subarrays of 3 3 2 4 1 2 have a sum EXACTLY equal to (their length) × (their minimum)?
- Why does the OR of a subarray change at most about log(maximum value) times as its right end extends from a fixed start?
- Why is the OR of a subarray always at least the maximum element of that subarray?
- When counting triangles from sorted stick lengths with a two-pointer scan, why does fixing the largest side k and moving the pointers i <…
- Why is the inequality test for a non-degenerate triangle with sorted sides written as ai + aj > ak for the largest side ak?