Data Structures & AlgorithmsModerateTCS NQT · Accenture

Looking from the right, a building is seen if it is strictly taller than every building to its right (the rightmost is always seen). How many buildings are seen in [5, 1, 6, 2, 4, 3]?

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

Correct answer: B. 3

Scan from the right with a running maximum: 3, then 4, then 6 each exceed the maximum so far, giving 3 buildings.

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

Exams that ask this topic