PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Ge

Count visible people to the right

Last updated: Mar 29, 2026

Quick Overview

This question evaluates algorithmic problem-solving with arrays and visibility relations, assessing competency in array traversal, handling of relative ordering constraints, and designing time- and space-efficient approaches.

  • medium
  • Ge
  • Coding & Algorithms
  • Software Engineer

Count visible people to the right

Company: Ge

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

## Problem You are given an array `heights` of length `n`, where `heights[i]` is the height of the `i`-th person standing in a line from left to right. For each index `i`, compute how many people to the **right** of `i` are **visible** to person `i`. ### Visibility rule Person `i` can see person `j` (`j > i`) if **every** person `k` with `i < k < j` is shorter than **both** `i` and `j`: - `heights[k] < min(heights[i], heights[j])` for all `k` between them. Equivalently (often easier to reason about): looking from `i` to the right, person `i` can see a sequence of shorter people, and they can also see the first person whose height is **greater than or equal to** `heights[i]` (and then visibility stops beyond that point). ### Input - Integer array `heights` (size `n`). ### Output - Integer array `ans` of size `n` where `ans[i]` is the number of visible people to the right of person `i`. ### Example - Input: `heights = [10, 6, 8, 5, 11, 9]` - Output: `[3, 1, 2, 1, 1, 0]` ### Constraints - `1 <= n <= 100000` - `1 <= heights[i] <= 10^9`

Quick Answer: This question evaluates algorithmic problem-solving with arrays and visibility relations, assessing competency in array traversal, handling of relative ordering constraints, and designing time- and space-efficient approaches.

Related Interview Questions

  • Minimize total distance to a store - Ge (medium)
Ge logo
Ge
Feb 11, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
2
0

Problem

You are given an array heights of length n, where heights[i] is the height of the i-th person standing in a line from left to right.

For each index i, compute how many people to the right of i are visible to person i.

Visibility rule

Person i can see person j (j > i) if every person k with i < k < j is shorter than both i and j:

  • heights[k] < min(heights[i], heights[j]) for all k between them.

Equivalently (often easier to reason about): looking from i to the right, person i can see a sequence of shorter people, and they can also see the first person whose height is greater than or equal to heights[i] (and then visibility stops beyond that point).

Input

  • Integer array heights (size n ).

Output

  • Integer array ans of size n where ans[i] is the number of visible people to the right of person i .

Example

  • Input: heights = [10, 6, 8, 5, 11, 9]
  • Output: [3, 1, 2, 1, 1, 0]

Constraints

  • 1 <= n <= 100000
  • 1 <= heights[i] <= 10^9

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Ge•More Software Engineer•Ge Software Engineer•Ge Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.