Practice/Meta/Leetcode 1762. Buildings With an Ocean View
CodingMust
You are given an array representing the heights of buildings standing in a row along a coastline. The ocean is located to the right of all buildings. A building has an ocean view if there are no buildings of equal or greater height anywhere to its right.
Return the indices of all buildings that have an ocean view, sorted in ascending order.
Example 1:
` Input: heights = [4, 2, 3, 1] Output: [0, 2, 3] Explanation:
Example 2:
Input: heights = [5, 4, 3, 2, 1] Output: [0, 1, 2, 3, 4] Explanation: Heights strictly decrease, so every building is taller than all buildings to its right.
Example 3:
Input: heights = [1, 2, 3, 4, 5] Output: [4] Explanation: Only the last building has a view since each prior building is blocked by a taller one to its right.