Number of Visible People in a Queue
A hard-tier problem at 71% community acceptance, tagged with Array, Stack, Monotonic Stack. Reported in interviews at Citigroup and 8 others.
Number of Visible People in a Queue shows up in live assessments at Google, LinkedIn, DoorDash, and Oracle. You're given heights and need to count how many people each person can see. The trap: the naive simulation feels right but times out. The actual solution uses a monotonic stack to process people in reverse, tracking who's visible in O(n) time. Most candidates either miss the stack pattern entirely or build it wrong under pressure. If you hit this cold in your assessment and freeze, StealthCoder surfaces the working approach instantly, invisible to the proctor.
Companies that ask "Number of Visible People in a Queue"
Number of Visible People in a Queue is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made by a working FAANG engineer who treats the OA the way companies treat hiring: as a game with rules you should know.
Get StealthCoderThe core trick is processing people from right to left and maintaining a decreasing stack. When you encounter someone taller, they block visibility for shorter people behind them, but they might still see the stack peek. The stack stores heights paired with their frequency (because people of the same height can see each other). As you move left, taller people 'pop' the stack and their visibility count accumulates. The pattern feels backward because you're not iterating forward through the queue. Common failure: trying to simulate visibility left-to-right, which balloons to O(n^2) or worse. The acceptance rate is 71 percent, which means the other 29 percent either timeout or hit edge cases around duplicate heights and how people of equal height contribute to each other's counts. This is a hard problem that rewards pattern recognition. If you've drilled monotonic stacks, you'll spot it. If not, StealthCoder gives you the solution the moment you need it.
Pattern tags
You know the problem.
Make sure you actually pass it.
Number of Visible People in a Queue recycles across companies for a reason. It's hard-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made by a working FAANG engineer who treats the OA the way companies treat hiring: as a game with rules you should know. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Number of Visible People in a Queue interview FAQ
Is this really asked at FAANG companies?+
Yes. Google, LinkedIn, DoorDash, and Oracle are all in the report. It's a classic hard-tier array problem that tests whether you know monotonic stack patterns. If you're prepping for any of those companies, this one matters.
What's the difference between this and a standard 'largest rectangle' stack problem?+
Here you're counting visibility between people, not finding extrema. The stack tracks heights and frequencies to handle ties correctly. Duplicate heights see each other, which breaks the typical monotonic pattern and is where most candidates slip.
Why doesn't a simulation work?+
Checking visibility for each person by scanning left until blocked is O(n^2) worst case. With n up to 10^5, you'll timeout. The monotonic stack avoids redundant comparisons by processing in reverse and maintaining invariants.
How do I know when to use a monotonic stack?+
When the problem asks you to find or count something relative to larger or smaller elements, and a greedy left-to-right or right-to-left order avoids redundant work. Stacks are efficient for this. This problem is a textbook case.
What trips people up on the acceptance rate?+
At 71 percent, it's the frequency tracking and how people of equal height contribute to counts. Off-by-one in the visibility formula and mishandling the stack pop logic are common. Edge cases like all same heights or descending arrays expose weak implementations fast.
Want the actual problem statement? View "Number of Visible People in a Queue" on LeetCode →