Google interview question

DFS based question with performance improvement.

Interview Answer

Anonymous

29 Oct 2021

I solved the question along with performance improvement. The reason for reject was missing boundary conditions.