Data Structures & AlgorithmsModerateTCS NQT · Infosys

Buildings of heights [5, 3, 8, 3, 2, 7, 9, 4] stand in a row viewed from the left. A building is visible if it is strictly taller than every building before it. How many buildings are visible?

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

Correct answer: B. 3

Track the running maximum and count each new strict record. Counting distinct heights, or viewing from the other side, answers different questions.

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

Exams that ask this topic