Databricks interview question

A problem that require to do BFS multiple times