You are given an array heights representing n people standing in a queue from left to right. Each value heights[i] is the height of person i, and all heights are unique.
A person at index i can see another person at index j (j > i) if everyone standing between them is shorter than both persons i and j.
In other words, person j is visible to person i if:
Your task is to return an array where each value answer[i] represents how many people person i can see looking to the right.
Input: heights = [12, 4, 7, 3, 15, 10]
Output: [2,1,1,1,1,0]
Explanation:
Person 0 sees persons 2 and 4 Person 1 sees 2 Person 2 sees 3 Person 3 sees 4 Person 4 sees 5 Person 5 sees no one
Input: heights = [9, 2, 6, 1, 5]
Output: [2,1,1,1,0]
Accepted:
Submission: