Josh Technologies OA | SDE 2022 Grad
Anonymous User
1641

A tree is considered special if the sums of all the nodes at each level are in an Arithmetic Progression (AP).
Given the root note of a binary tree. Return an array representing the minimum number that can be added at each level to make that tree special.

We need to solve it in O(N) time and O(1) space.
Bonus : We can't store the sums at each level.

Example -
Input 1:

         3
        /   \
       2     7
	   \
	    15

Output: [0, 0, 0] since the sums were already in AP. {3, 9, 15}

Input 2:

          1
        /   \
      11     5
	  / \     \
	 2   15    10
	  \
      50

Output: [0, 0, 19, -4].

Comments (6)