For a team page, people stand in a row from left to right with distinct heights heights. Person i can see person j to their right (i < j) if everyone standing between them is shorter than both of them.
Write visibleCounts(heights) that returns an array where position i is how many people to the right person i can see.
Input: heights = [10,6,8,5,11,9] Output: [3,1,2,1,1,0]
Person 0 sees 6, 8, and 11; 5 is hidden behind 8, and 9 behind 11.
Input: heights = [5,1,2,3,10] Output: [4,1,1,1,0]
Person 0 sees everyone: each person between is shorter than both.
1 <= heights.length <= 10^51 <= heights[i] <= 10^5Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #270 Who Can See Whom in a Team Photo. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.