Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA

Buildings of heights [4, 1, 6, 2, 5, 3] are viewed from the right. How many are visible (strictly taller than every building to their right)?

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

Correct answer: C. 3

Scan from the right and record each strict prefix maximum. The visible buildings from the right are 3, 5 and 6, so the count is 3.

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

Exams that ask this topic