PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Uber

Find robots matching obstacle-distance signature

Last updated: Mar 29, 2026

Quick Overview

This question evaluates spatial reasoning on 2D grids, the ability to compute distance signatures to nearest obstacles, and careful handling of boundary and edge-case conditions.

  • hard
  • Uber
  • Coding & Algorithms
  • Software Engineer

Find robots matching obstacle-distance signature

Company: Uber

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Technical Screen

You are given a 2D grid and a distance signature `dist = [left, top, bottom, right]`. ## Grid Each cell is one of: - `O` : a robot - `E` : empty - `X` : obstacle The **boundary outside the grid is also considered an obstacle** (i.e., moving off the grid in any direction hits an obstacle immediately). ## Distance signature For any cell `(r, c)`, define: - `left` = the number of **non-obstacle cells** strictly between `(r,c)` and the nearest obstacle when moving left in the same row. - `top` = the number of non-obstacle cells strictly between `(r,c)` and the nearest obstacle when moving up in the same column. - `bottom` = the number of non-obstacle cells strictly between `(r,c)` and the nearest obstacle when moving down in the same column. - `right` = the number of non-obstacle cells strictly between `(r,c)` and the nearest obstacle when moving right in the same row. Notes: - If the adjacent cell in that direction is an obstacle (or you would immediately leave the grid), the distance in that direction is `0`. - Obstacles (`X`) block the line of sight; only the nearest obstacle in that direction matters. ## Task Return the coordinates of **all robots** (`O` cells) whose distance signature equals the given `dist`. ## Input / Output (you may assume) - Input: `grid` as an `R x C` matrix of characters, and integer array `dist` of length 4. - Output: a list of coordinates `[(r1,c1), (r2,c2), ...]` for all matching robots (any order). ## Constraints (reasonable interview assumptions) - `1 <= R, C <= 2000` - `grid[r][c] ∈ { 'O', 'E', 'X' }` - `0 <= dist[i] <= max(R,C)`

Quick Answer: This question evaluates spatial reasoning on 2D grids, the ability to compute distance signatures to nearest obstacles, and careful handling of boundary and edge-case conditions.

Related Interview Questions

  • Maximize Throughput and Count Trigger Components - Uber (medium)
  • Replace Dashes With Nearest Letters - Uber (medium)
  • Find Earliest Column With One - Uber (easy)
  • Solve Wonderful Strings and Grid Queries - Uber (hard)
  • Count Islands After Land Additions - Uber (medium)
Uber logo
Uber
Jan 20, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
8
0
Loading...

You are given a 2D grid and a distance signature dist = [left, top, bottom, right].

Grid

Each cell is one of:

  • O : a robot
  • E : empty
  • X : obstacle

The boundary outside the grid is also considered an obstacle (i.e., moving off the grid in any direction hits an obstacle immediately).

Distance signature

For any cell (r, c), define:

  • left = the number of non-obstacle cells strictly between (r,c) and the nearest obstacle when moving left in the same row.
  • top = the number of non-obstacle cells strictly between (r,c) and the nearest obstacle when moving up in the same column.
  • bottom = the number of non-obstacle cells strictly between (r,c) and the nearest obstacle when moving down in the same column.
  • right = the number of non-obstacle cells strictly between (r,c) and the nearest obstacle when moving right in the same row.

Notes:

  • If the adjacent cell in that direction is an obstacle (or you would immediately leave the grid), the distance in that direction is 0 .
  • Obstacles ( X ) block the line of sight; only the nearest obstacle in that direction matters.

Task

Return the coordinates of all robots (O cells) whose distance signature equals the given dist.

Input / Output (you may assume)

  • Input: grid as an R x C matrix of characters, and integer array dist of length 4.
  • Output: a list of coordinates [(r1,c1), (r2,c2), ...] for all matching robots (any order).

Constraints (reasonable interview assumptions)

  • 1 <= R, C <= 2000
  • grid[r][c] ∈ { 'O', 'E', 'X' }
  • 0 <= dist[i] <= max(R,C)

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Uber•More Software Engineer•Uber Software Engineer•Uber 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.