Data Structures & AlgorithmsModerate
How many contiguous subarrays of 4 2 6 2 5 3 2 7 contain EXACTLY one occurrence of the global minimum value 2?
- A. 16
- B. 30
- C. 14
- D. 13
Correct answer: A. 16
Count the occurrences of the global minimum inside each block and keep the blocks with exactly one. Blocks containing the minimum at all, blocks with two or more copies, or excluding singletons each give other totals.
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
- Add up the LENGTHS of all contiguous subarrays of 1 3 2 2 5 4 6 that are non-decreasing (each qualifying subarray contributes its length…
- How many contiguous subarrays of 5 2 7 3 9 4 1 of length at least 2 have pairwise DISTINCT values, and whose FIRST element is their maximum?
- What is the maximum sum of a contiguous subarray of 4 9 1 6 3 2 8 5 that has length at least 2 and whose sum is divisible by 5?
- What is the length of the shortest contiguous subarray of 3 8 1 5 8 2 3 7 whose two END elements are equal?
- How many contiguous windows of length exactly 3 in 4 1 5 1 6 2 2 9 contain their minimum value AT LEAST TWICE?
- Count the pairs of positions i < j in 2 5 3 2 4 5 6 3 with EQUAL values such that the value does not occur strictly between them (i and j…