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)?

  1. A. 4
  2. B. 5
  3. C. 3
  4. 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.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic