Workday Interview Question

something could be solved with bfs