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?
- A. 2
- B. 1
- C. 0
- 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
- Problem: The string "racecarxyz" is examined for palindromic substrings of length at least 5. How many such palindromic substrings are…
- Problem: The number of ways to arrange the letters of "LEVEL" so that the two E's are not adjacent is what value?
- Problem: Consider the sequence 1, 4, 9, 16, … of perfect squares. What is the smallest square that is greater than 500 and also ends in…
- Problem: How many 4-letter strings over {A, B, C} have no letter appearing more than twice?
- Problem: The binary tree with root 10, left child 5, right child 15, and 5 having right child 7, 15 having left child 12, is traversed in…
- Problem: A list starts as [8, 3, 5]. Three insertion steps add the numbers 4, 9, 1 at the front of the list (each is inserted at index 0)…