Data Structures & AlgorithmsHard
How many contiguous windows of length exactly 2 in 4 7 2 9 3 5 11 8 have BOTH values prime?
- A. 3
- B. 7
- C. 4
- D. 2
Correct answer: A. 3
Each length-2 window needs both its values prime, and 1 is not prime so it never qualifies. Using OR instead of AND, adding a distinctness rule that is not asked, or comparing positions two apart each change the answer.
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
- Why does the two-transaction stock problem split the array at a point and solve each side independently?
- When the maximum and minimum must end at the two extremes by adjacent swaps, why can their costs interact?
- Why does 'maximum number of disjoint zero-sum blocks' use an interval DP over prefixes rather than a greedy scan?
- To count subarrays of length at least 2 with equal odd and even counts, why is the length-1 case excluded?
- Why is the minimum over all rotations of a permutation's inversion count achieved by a specific rotation that can be found in linear time?
- When covering all distinct values of an array with a subarray, why does a sliding window track counts rather than a single flag?