Can someone please explain this test case?


  • 0
    J

    I'm failing this test case and can't figure out the logic behind it.

    [1,2,3,4,null,5]
    expected: 11

    I believe it is test case 13.

    Here is the tree:

            *
         /      \
       1        2
     /   \     /   \
    3    4   n      5
    

    The 2-node gets a tilt of (5 - null = 5) and a sum of (5 + null + 2 = 7). The 1-node gets a tilt of (4 - 3 = 1) and a sum of (3 + 4 + 1 = 8).

    The root node gets a tilt of 8-7=1. The sum of the tilts is 1+1+5 = 7. Where is the 11 coming from?


  • 0
    S

    @Jacob.Lista The tree you have posted is wrong! Check the visualizer again, "1" is the root of the tree.


  • 0
    R

    @Jacob.Lista The representation of the test case as a binary tree is wrong. '1' is the root node,'2' &'3' is the children node of root and so on. '3' has only one child i.e '5' as its left child. Hope this helps.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.