Number of Visible People in a Queue
Hard · Stack & Monotonic Stack · about 25 minutes
Asked at Google, Oracle, Salesforce, ByteDance, Amazon, ServiceNow, Workday.
n people stand in a queue facing right; heights[i] are distinct. Person i can see person j > i if everyone between them is shorter than both. Return, for each person, how many people they can see to their right.