JUSPAY interview question

Question 3 based on tree and graph difficult