Back to problems

Count Visible People for Every Person

Algorithm · Google · Hard

The array heights describes people standing in a row, listed from left to right. For each person, work out how many of the other people they are able to see, and return these counts as an array answer. Two people at positions i and j can see one another exactly when every position k lying strictly between them satisfies heights[k] <= max(heights[i], heights[j]). Put differently, someone in the middle blocks the view only if they are strictly taller than both of the two…

Loading the rest of the question…