Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys

Problem: A list of numbers is [10, 4, 9, 7, 5, 12]. A "peak" is an element strictly greater than both of its neighbours (end elements have only one neighbour and are not counted). How many peaks are there?

  1. A. 2
  2. B. 1
  3. C. 0
  4. D. 3

Correct answer: B. 1

Test each interior element against both neighbours. Element 9 is a peak; 7 is not because it is smaller than 9 on the left.

More Coding Interview Problems questions

Exams that ask this topic