How Many Attendees Each Person Sees in a Live Event Queue
Last updated: November 29, 2026
Quick Overview
People stand in a line facing right with distinct heights. Person i can see person j > i if everyone between them is shorter than both; return how many people each person can see.
Meta
November 29, 20260
0
0 solved
People stand in a line facing right with distinct heights. Person i can see person j > i if everyone between them is shorter than both; return how many people each person can see.
A Meta onsite Hard framed around sightlines in a line for a live event, a variation on next-greater problems where you must count everyone visible, not just the first blocker. The interviewer checks that you see that visible people form a decreasing stack from the right and count pops plus one.
What the Interviewer Expects
- Characterize who is visible: a sequence of increasing heights up to and including the first taller person
- Scan right to left with a decreasing stack
- Count each popped person as visible
- Add one if someone taller remains on the stack
- Prove O(n) amortized time
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- What if heights can repeat and an equal height blocks the view?
- Return the list of visible indices, not just counts.
- People face both directions: count total visible pairs.
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: list h of distinct positive heights, length up to 10^5. Output: list see where see[i] counts j > i such that min(h[i], h[j]) > max(h[i+1..j-1]). Adjacent people always see each other....
High-Level Design
From person i looking right, the visible people are the prefix maxima of the line to the right, stopping at the first person taller than i (who is visible but blocks everyone behind). Scan right to le...