Waymo interview question

Solve a grid based C++ question