Amazon OA - Move the Obstacle

You are in charge of preparing a recently purchased lot for the Company's building.
The lot is covered with trenches and has a single obstacle that needs to be taken down before the foundation is prepared for the building.
The demolition robot must remove the obstacle before the progress can be made on the building.

The lot is flat, except the trenches, and can be represented by a 2D grid.
The demolition robot must start at the top left corner of the lot, which is always flat, and can move on the block up, down, right, left
The demolition robot cannot enter trenches and cannot leave the lot.
The flat areas are indicated by 1, areas with trenches are indicated by 0, and the obstacle is indicated by 9

The input consists of three arguments:
numRows: an integer represents the number of rows
numColumns: an integer represents the number of columns
lot: a 2d grid of integers

Return an integer that indicated the minimum distance traversed to remove the obstacle else return -1

1<= numRows
numColumns <= 1000

numRows = 3
numColumns = 3
lot = [
[1, 0, 0],
[1, 0, 9],
[1, 9, 1]
Output: 3
Starting from the top-left corner, the demolition robot traversed the cells (0,0) -> (1,0)-> (2,0)->(2,1)
The robot moves 3 times to remove the obstacle 9

More Amazon Online Assessment Questions 2021

Get one-to-one training from Google Facebook engineers

Top-notch Professionals

Learn from Facebook and Google senior engineers interviewed 100+ candidates.
Most recent interview questions and system design topics gathered from aonecode alumnus.
One-to-one online classes. Get feedbacks from real interviewers.

Customized Private Class

Already a coding expert? - Advance straight to hard interview topics of your interest.
New to the ground? - Develop basic coding skills with your own designated mentor.
Days before interview? - Focus on most important problems in target company question bank.