Uber Interview Question

Coding question on a 2D grid.