TuSimple Interview Question

it's a BFS question I think, would be done with recursion as well