Pergunta de entrevista da empresa TuSimple

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