Data Structures & AlgorithmsModerate
How many index pairs i < j in 2 3 1 4 5 2 6 have the closed block A[i..j] strictly increasing (with j > i)?
- A. 5
- B. 15
- C. 4
- D. 6
Correct answer: A. 5
The whole block must be strictly increasing, not just its endpoints, so each step inside has to be checked. Comparing only the endpoints, allowing equal neighbours, or counting adjacent steps each measure different sets.
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 contiguous windows of length exactly 3 in 4 1 2 3 9 8 6 7 are strictly monotone (increasing or decreasing) AND contain the global…
- Choose two NON-OVERLAPPING non-empty contiguous subarrays of 2 -3 5 1 -2 4 -1 3, one entirely to the left of the other. What is the…
- What is the length of the longest contiguous subarray of 2 0 1 3 1 1 2 0 in which the sum of (element − 1) over the subarray equals 0?
- How many positions i with 1 ≤ i ≤ n−2 in 5 3 6 2 7 4 8 1 9 are STRICT local minima (strictly smaller than both neighbours)?
- How many contiguous windows of length exactly 2 in 2 3 1 4 2 5 0 3 have a PRODUCT strictly greater than their SUM?
- How many contiguous windows of length exactly 3 in 6 10 15 4 9 7 14 3 have their three values PAIRWISE coprime (every two of them have gcd…