Pergunta de entrevista da empresa Amazon

The question was direct from gfg which is maximum sum tree.