Workday interview question

something could be solved with bfs