Count how many people in an array of heights are visible to the last person.
Unlock detailed company stats for this questionUpgrade
Given an array representing the heights of people, determine how many people are visible to the last person in the array.
Rule: person A is visible to person B if there is no one between them who is taller than both A and B.
Example: input [1, 10, 5, 7, 6, 3, 2, 4] gives output 5, since the people with heights 2, 3, 6, 7 and 10 are visible to 4.
Follow-up: find the number of visible people for every person in the list, not just the last one.
Goal: an optimized O(n) time solution for both cases.
Expect follow-ups like
- Find the number of visible people for every person in the list, in O(n).
Community answers
No answers contributed by the community yet.
Related questions
Count how many people report to the nth manager.How many people are flying to and from SFO in a day?Related courses

Course

Course
