Data Structures & AlgorithmsHard
How many contiguous subarrays of 2 5 1 5 3 4 contain the maximum VALUE of the subarray exactly once?
- A. 15
- B. 6
- C. 9
- D. 16
Correct answer: A. 15
For each subarray count how many times its maximum value appears; the answer keeps blocks where that count is one. Counting blocks with repeated maxima, testing distinctness, or dropping singletons gives 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
- What is the length of the shortest contiguous subarray of 1 4 4 2 2 1 3 whose sum is at least 9?
- Among the contiguous windows of length exactly 3 in 2 4 1 6 3 8 5 10 that contain at most one ODD number, what is the largest window sum?
- Choose three DIFFERENT positions from -4 -1 1 2 5 7 and add their values. Among all such three-element sums that are closest to 3 (in…
- How many contiguous subarrays of 4 2 3 6 5 7 1 have length equal to (maximum − minimum + 1)?
- What is the length of the longest contiguous subarray of 3 -2 0 4 -1 0 2 -5 in which the number of positive elements equals the number of…
- A window with at most K replacements (or at most K zeros) is found with two pointers. Why is it safe for the left pointer to only move…