Data Structures & AlgorithmsModerateTCS NQT · Accenture
Buildings of heights 3, 7, 8, 3, 6, 1 stand in a row. A building is visible from the left if no building to its left is at least as tall. How many buildings are visible from the left?
- A. 3
- B. 2
- C. 4
- D. 5
Correct answer: A. 3
Visible buildings are the strict prefix maxima: a building counts only if it is strictly taller than every building before it. Equal-height buildings are hidden.
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 length of the longest contiguous subarray of [4, 2, 4, 5, 6, 2, 4, 1] that contains no repeated value?
- How many contiguous subarrays of [4, 5, 0, -2, -3, 1] have a sum divisible by 4?
- How many distinct values v in the array [1, 2, 2, 3, 3, 3, 4, 4, 4, 4] occur exactly v times?
- What is the length of the longest common prefix of the strings interstellar, internet, interval and intern?
- How many integers x with 1 <= x <= 100 satisfy x mod 3 = 2 and x mod 5 = 3?
- How many contiguous subarrays of [7, 1, 6, 13, 8, 2] have a sum congruent to 0 modulo 7?