Amazon Interview Question

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