This was a four-round technical interview in a row, and one can’t help but be impressed by Google’s interview rigor and efficiency. Today Dr. Shi shares one of the high-frequency questions—many candidates stumble by not reading the prompt carefully, and it’s a favorite of interviewers.
Original Question (English)
Imagine there are n people waiting in a line, all facing the same direction. Each person has a different height. A person A can see another person B in front of them if there is no one taller than both A and B standing between them.
Q1: How many people can the last one in line see? Example: Input: [1, 10, 6, 7, 9, 8, 2, 4, 3, 5] Output: 6
High-Frequency Tip: This problem has appeared multiple times in recent Google VO interviews. For common misconceptions about “line-of-sight blocking,” see this note.
We use AI-mediated eye contact in Google Meet to let candidates interact with the interviewer’s gaze, so they can still view the code hints we’ve prepared without interruption.
Clarifications
Can we assume the input list is non-empty?
Algorithmic Approach
We can solve this by a single pass from the viewer toward the front:
Start from the person immediately in front of the viewer (the last person) and move left (toward the front).
Keep track of the tallest height seen so far between the viewer and the current person.
If a person’s height exceeds that “tallest so far,” they are visible.
Continue until you reach the front of the line, counting all visible people.
After reading this, the candidate restated the approach in their own words to the interviewer, who was very satisfied and invited them to code.
def count_visible(heights):
# Get the height of the last person (the viewer)
viewer_height = heights[-1]
# Initialize the counter for how many people the viewer can see
visible_count = 0
# Keep track of the tallest person seen so
# far between the viewer and the person being evaluated
tallest_so_far = 0
# Traverse from the second last person to the
# front (left to right from the viewer's perspective)
for i in range(len(heights) - 2, -1, -1):
person_height = heights[i]
# Rule: viewer can see this person if there's no
# one taller than both viewer and target in between
if person_height > tallest_so_far or viewer_height > tallest_so_far:
# Update the tallest seen so far
tallest_so_far = person_height
# Check if this person is visible to the
# viewer (they must not be taller than the viewer)
if person_height <= viewer_height:
visible_count += 1
# Also: if this person is taller than the
# viewer, they block further view
# but we still count them if they're the tallest seen so far
elif person_height > viewer_height:
visible_count += 1
return visible_count
Since we’ve practiced this problem many times, we quickly drafted the following support code with detailed comments for clear communication:
Maintain eye contact, think aloud as you code, and proactively ask about edge cases and input constraints to demonstrate rigor. After the interview, CSOahelp will send you the key points to review, helping you prepare even better for the next round.
Across all four rounds, the interviewers were very impressed. We look forward to celebrating good news soon!
If you’re also preparing algorithm or system-design interviews at top companies like Apple, Meta, or TikTok and need guidance on problem breakdowns or handling edge cases, contact us to receive North American interview and job-hunting tips. We also offer mock interviews, interview assistance, and coding-challenge support to help you land your dream job!