Uber | SDE-2

Anonymous User
2897
Jul 06, 2022
Jul 06, 2022

Recently interviewed at Uber and was asked the following question:

Given a 2D matrix of integers having only 0, 1 and 2.

0 repesents empty space
1 repesents robot
2 repesents blocker

There can be many robots in the matrix. The task was to return all the robots as per the query below:

[2, 4, 3, 5] which means return all robots which have blockers at distance:
2 on the left from the current position of the robot
4 at the top from the current position of the robot
3 on the right from the current position of the robot
5 at the bottom from the current position of the robot

There can be several such queries.

Was able to come up with a simple brute-force solution. But later got a hint from the interviewer that it can be solved using DP.

What could be the DP solution for this? Also, any tips to analyse and come up with a DP solution in an interview will be appreciated.

Comments (4)