Google interview question

A Leetcode medium problem on bfs.