Josh Technology Group (JTG) | Virtual | SDE| Round 3 Special Binary Tree | 2022
Anonymous User
1984

Problem Statement

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

Input 1 :

 3
/  \
2  7
\
 15

Output: [0, 0, 0]

Input 2 :

  17
 /  \
11   5
       \
	   12

Output : [0,0,3]

Input 3 :

   1
  /  \
 11   5
/      \
2      10
\
 50

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

Time : O(n)
Space: O(n)

Do share your appraoch guys & please upvote if you like it.

Happy Coding

Comments (2)