Data Structures & AlgorithmsHard
How many contiguous subarrays of 1 5 2 7 3 4 8 contain EXACTLY one element whose value is at least 5?
- A. 13
- B. 23
- C. 15
- D. 8
Correct answer: A. 13
Count the elements at least 5 inside each subarray and keep the blocks with exactly one. Using at-least-one, using a strict bound of 5, or allowing two large values each change the total.
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 minimum number of characters to delete from "aabbbcaa" so that no two ADJACENT characters are equal?
- How many contiguous windows of length 3 in 5 3 4 6 2 7 1 8 are STRICTLY monotone (strictly increasing or strictly decreasing)?
- How many adjacent pairs (A[i], A[i+1]) in 4 7 2 9 1 8 5 6 have a sum of at least 10?
- In the 'maximum number of disjoint pairs with sum K' problem, why is a count-based greedy optimal?
- To find the longest subarray in which every value appears an even number of times, why can a parity bitmask over values be used with…
- Why is the minimum number of adjacent swaps to make a string palindromic NOT simply half the number of mismatched mirror pairs?