Compute nearest gate distance in grid | Robinhood Interview Question