Data Structures & AlgorithmsModerateTCS NQT · Accenture

Buildings of heights 3, 7, 8, 3, 6, 1 stand in a row. A building is visible from the left if no building to its left is at least as tall. How many buildings are visible from the left?

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

Correct answer: A. 3

Visible buildings are the strict prefix maxima: a building counts only if it is strictly taller than every building before it. Equal-height buildings are hidden.

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

Exams that ask this topic