Uber screening round
Company: Uber
Role: Software Engineer I, Software Engineer II
Interview Stage: Phone Screen
Location: unknown
Year: unknown
Original Post Content:
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 blocker, 2 to the top blocker, 4 to the bottom blocker and 1 to the right 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.
Return the coordinates of all robots who can satisfy move given by second input.
Is there any leetcode equivalent of this problem?
I proposed solution which goes linearly through the location map, for each robot detected, we would do boundary check and return the result. Time complexity of such solution would be O(m*n*max(secondInputValues)).
Is there any better solution than this?