Uber interview question

Coding question on a 2D grid.