Uber Sr Software Engineer hyderabad Phone Screen Round
Summary
This post details a specific coding question encountered during a phone screen round for a Senior Software Engineer position at Uber in Hyderabad.
Full Experience
Given two inputs, First input is the location map, a 2D array
| O | E | E | E | X | | E | O | X | X | X | | E | E | E | E | E | | X | E | O | E | E | | X | E | X | E | X |
O = Robot, E = Empty, X = Blocker
Second input is the query. It’s a 1D array consisting of distance to the closest blocker in the order from left, top, bottom and right
[2, 2, 4, 1] -> This means distance of 2 to the left closest blocker, 2 to the top closest blocker, 4 to the bottom closest blocker and 1 to the right closest blocker
Note: The location map boundary is also considered blocker, meaning if the robot hits the boundary it also means it’s hitting the blocker.
Write a function that takes these two inputs and returns the index of the robots (if any) that matches the query that we’re looking for.
Example -
Solution for the example above would be the robot located at index [1, 1]
| O | E | E | E | X | | E | >O< | X | X | X | | E | E | E | E | E | | X | E | O | E | E | | X | E | X | E | X |
Interview Questions (1)
Given a 2D map with robots ('O'), empty spaces ('E'), and blockers ('X'), and a query array representing distances to the closest blocker in four directions (left, top, bottom, right).
The map boundaries are also considered blockers. The task is to write a function that takes the map and the query, and returns the indices of all robots that satisfy the given blocker distance query.
Example: Map: | O | E | E | E | X | | E | O | X | X | X | | E | E | E | E | E | | X | E | O | E | E | | X | E | X | E | X |
Query: [2, 2, 4, 1] (distance to left, top, bottom, right blockers respectively)
Expected Output: Robot at index [1, 1]