Visible to the Right
People stand in a row and heights[i] is the height of the person at position i. Everyone looks to the right. Person i can see person j (with j > i) when every person standing strictly between them is shorter than both heights[i] and heights[j]. Neighbours always see each other, and a person of equal or greater height in between blocks the view.
Return a list where item i is the number of people person i can see. The last person sees nobody. Return an empty list for an empty row.
Example 1
Person 0 (height 10) sees the people of height 6, 8 and 11; the 11 hides everyone after it. Person 2 (height 8) sees 5 and 11.
Example 2
Person 0 (height 5) sees everyone, because 1, 2 and 3 rise without blocking and the 10 is at the end.
Constraints
0 <= len(heights) <= 1001 <= heights[i] <= 1000
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.