Data Structures & AlgorithmsHard
How many contiguous windows of length 3 in 5 3 4 6 2 7 1 8 are STRICTLY monotone (strictly increasing or strictly decreasing)?
- A. 6
- B. 2
- C. 1
- D. 0
Correct answer: C. 1
A length-3 window is strictly monotone when both consecutive steps go the same strict direction. Counting only increasing windows misses the decreasing ones, and non-strict comparisons admit repeated values.
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 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?
- When repeatedly deleting adjacent pairs of different letters, why does the final length have fixed parity?
- In the 'shortest block to sort so the whole array becomes sorted' problem, why does the block start at the first mismatch with the sorted…