Back to problems

Count People Visible to the Last Person

Algorithm · Google · Medium

Problem The array heights describes a row of people standing from left to right. Count how many of the other people the person at the end of the row can see. Two people at positions i and j are able to see each other when nobody standing between them is strictly taller than both of them. Put another way, every position k lying between i and j must satisfy: heights[k] <= max(heights[i], heights[j]). The last person looks only toward the left, and does not count as visible to…

Loading the rest of the question…