Data Structures & AlgorithmsHardGATE CS · TCS NQT

How many elements of [1, 5, 2, 8, 3, 9, 4] are strict local maxima (strictly greater than both neighbours; the two end elements are excluded)?

  1. A. 4
  2. B. 3
  3. C. {C-1}
  4. D. 5

Correct answer: B. 3

Check each interior element against both neighbours; the values 5, 8 and 9 qualify. Including the ends would wrongly add 1 or 4.

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

Exams that ask this topic