Databricks interview question

graph question - traversal and hashmap and optimzation