Problem statement

https://binarysearch.com/problems/Unobstructed-Buildings/

Solution

Equal to Leetcode 1762 Buildings With an Ocean View.

Complexity

Time and space complexity is O(n).

Code

class Solution:
    def solve(self, H):
        n, ans = len(H), []
        for i in range(n-1, -1, -1):
            if not ans or H[i] > H[ans[-1]]:
                ans += [i]
                
        return ans[::-1]