Data Structures & AlgorithmsHard
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)?
- A. 4
- B. 5
- C. 3
- D. 6
Correct answer: A. 4
A strict local minimum is smaller than both neighbours, which is checked at interior positions only. Non-strict comparisons, adjacent increases, or adding the endpoints each change the count.
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 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…
- How many subsequences of EXACTLY three elements of 6 10 15 4 9 (position subsets) have gcd equal to 1?
- How many contiguous windows of length exactly 2 in 4 7 2 9 3 5 11 8 have BOTH values prime?
- Why does the two-transaction stock problem split the array at a point and solve each side independently?
- When the maximum and minimum must end at the two extremes by adjacent swaps, why can their costs interact?