Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: In the array [3, 1, 4, 1, 5, 9, 2, 6] an element is visible from the left if it is strictly greater than every element before it. How many elements are visible from the left?

  1. A. 4
  2. B. 5
  3. C. 3
  4. D. 6

Correct answer: A. 4

Track the running maximum and count strictly larger elements. Counting elements greater than the first element alone gives a different number.

More Coding Interview Problems questions

Exams that ask this topic