BharatPe interview question

based on trees, graphs and dynamic programming