Google Cloud interview question

Question on bfs arranging arrays