Problem Statement
There are n people standing in a queue, numbered from 0 to n-1 from left to right. You are given an array heights of distinct positive integers where heights[i] represents the height of the i-th person. The i-th person can see the j-th person (where j > i) if everybody in between is shorter than both of them. More formally, the i-th person can see the j-th person if i < j and min(heights[i], heights[j]) > max(heights[i+1], ..., heights[j-1]).[1][3][5]
Input/Output Examples
Example 1:
Input: heights =[5][6][8][9][10]
Output:[2][3][1]
Explanation: Person 0 sees persons 1, 2, 4; person 1 sees person 2; person 2 sees persons 3, 4; person 3 sees person 4; person 4 sees person 5; person 5 sees no one.[3][1]
Example 2:
Input: heights =[10][1][2][3][5]
Output:[4][1]
Explanation: Person 0 sees all to the right until blocked; others see until the tallest at the end.[5]
Constraints