PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates a candidate's ability to reason about grid traversal, boundary conditions, directional visibility counting, and constraint-based filtering to identify feasible positions.

  • medium
  • Uber
  • Coding & Algorithms
  • Software Engineer

Find possible robot positions

Company: Uber

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given a 2D grid where `'.'` represents an open cell and `'#'` represents a wall. A hidden robot is standing on one open cell. The robot's sensor returns four integers: `up`, `down`, `left`, and `right`. - `up`: how many open cells the robot can move upward before hitting a wall or leaving the grid - `down`: how many open cells the robot can move downward before hitting a wall or leaving the grid - `left`: how many open cells the robot can move left before hitting a wall or leaving the grid - `right`: how many open cells the robot can move right before hitting a wall or leaving the grid Write a function to return all open cells `(row, col)` that could be the robot's position given the grid and the four sensor values. Use zero-based indexing. A candidate cell is valid only if the visible open-cell counts in all four directions exactly match the given sensor readings.

Quick Answer: This question evaluates a candidate's ability to reason about grid traversal, boundary conditions, directional visibility counting, and constraint-based filtering to identify feasible positions.

You are given a 2D grid where '.' represents an open cell and '#' represents a wall. A hidden robot is standing on one open cell. The robot's sensor returns four integers: up, down, left, and right. Each value is the number of consecutive open cells the robot could move in that direction before hitting a wall or leaving the grid. Return all open cells [row, col] that could be the robot's position. A candidate cell is valid only if its visible open-cell counts in all four directions exactly match the given sensor readings. Use zero-based indexing, and return the positions in row-major order.

Constraints

  • 0 <= len(grid) <= 500
  • If grid is non-empty, 0 <= len(grid[i]) <= 500 for every row i
  • All rows in grid have the same length
  • grid[i][j] is either '.' or '#'
  • 0 <= up, down, left, right <= 500

Examples

Input: (['...', '.#.', '...'], 1, 1, 0, 0)

Expected Output: [[1, 0], [1, 2]]

Explanation: Cells (1,0) and (1,2) each have one open cell above, one below, and walls or boundaries immediately to the left and right.

Input: (['....'], 0, 0, 1, 2)

Expected Output: [[0, 1]]

Explanation: In the single row, cell (0,1) has one open cell to its left and two open cells to its right, with no cells above or below.

Input: (['.'], 0, 0, 0, 0)

Expected Output: [[0, 0]]

Explanation: The only open cell has no open cells visible in any direction.

Input: (['###', '###'], 0, 0, 0, 0)

Expected Output: []

Explanation: There are no open cells where the robot could stand.

Input: (['..#..', '...#.', '#....', '..#..'], 2, 1, 0, 3)

Expected Output: [[2, 1]]

Explanation: Cell (2,1) has two open cells upward, one downward, zero to the left because of a wall, and three open cells to the right.

Input: ([], 0, 0, 0, 0)

Expected Output: []

Explanation: An empty grid has no possible robot positions.

Hints

  1. For any open cell, each sensor reading is the length of a contiguous run of '.' cells in one direction, excluding the cell itself.
  2. Precompute vertical counts for each cell. Horizontal counts can be found efficiently by scanning each row's contiguous open segments.
Last updated: Jun 20, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ 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.

Related Coding 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)