Data Structures & AlgorithmsHardGATE CS · TCS NQT

Buildings of heights [3, 7, 8, 3, 6, 1] are viewed from the left. How many buildings are visible (a building is visible if it is strictly taller than every building before it)?

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

Correct answer: B. 3

Visibility is a prefix-maximum record count: each new strict maximum is visible. A monotonic stack gives the same answer, and reversing the view direction changes the count.

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

Exams that ask this topic