Ctrl K

Behind a Tall Building

Easy
Buildings stand in a row along a street, and heights[i] is the height of building i (0-based). The wind blows from the start of the street, so a building is sheltered when the building **right before it** is taller than limit (strictly). Building 0 has nothing in front of it and is never sheltered. Return the indices of all sheltered buildings in any order.
Example 1
heights=[4, 9, 2, 7, 6], limit=5 → [2, 4]

Only buildings 1 (height 9) and 3 (height 7) are taller than 5, so the buildings right after them, 2 and 4, are sheltered.

Example 2
heights=[3, 3, 3], limit=3 → []

A height strictly above 3 is needed, and no building has one.

Example 3
heights=[50, 1], limit=10 → [1]
Constraints
  • 2 ≤ len(heights) ≤ 100
  • 1 ≤ heights[i] ≤ 100
  • 1 ≤ limit ≤ 100
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPair With a Target Sum EasySqueeze Repeats Out of a Sorted Array EasyDrop the Unwanted Value EasySlot on a Sorted Shelf EasyAdd One to a Digit Array Easy
loading Python…
Input
heights=[4, 9, 2, 7, 6], limit=5
Expected
[2, 4]

Run checks the first 3 tests in your browser. Submit checks all 112 tests on the server, hidden ones included.