DoorDash interview question

Problem similar to Leetcode Walls and Gates