Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: The array [2, 7, 4, 1, 8, 1] is examined by a sweep: for each index i, the value a[i] is compared with the minimum of the elements to its left (for i = 0 no comparison). How many indices satisfy a[i] < min of all earlier elements?

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

Correct answer: B. 1

Track the running minimum of the prefix and count strict new lows. The second 1 is not a new low because it equals the existing minimum.

More Coding Interview Problems questions

Exams that ask this topic