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)?
- A. 4
- B. 2
- C. 3
- 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.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- What is the smallest positive integer m such that the sum of ceil(ai / m) over a = [7, 11, 12] is at most 9?
- How many ordered pairs (x, y) with 1 <= x, y <= 12 have x y divisible by 12?
- From the multiset [6, 1, 4, 2, 5, 3], choose as many elements as possible (order irrelevant) with total at most 10. What is the maximum…
- How many times does "ab" occur as a substring of the string "aab" repeated three times?
- How many distinct values arise as a sum of two different elements (by position) of [3, 5, 8, 10]?
- For [1, 3, 2, 4, 6, 5, 7], how many positions already hold their correct value in the sorted array?