Amazon interview question

Burning tree question from leetcode