Uber | SDE-2

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2022-07-06Added By Anonymous
Source: Link

Company: Uber
Role: Software Engineer II
Interview Stage: Phone Screen
Location: unknown
Year: unknown

Original Post Content:

Recently interviewed at Uber and was asked the following question:

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

0 represents empty space
1 represents robot
2 represents 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