Databricks interview question

BFS Graph Medium question, DSA