Function to perform every possible split and calculate absolute difference of subtrees
preOrder ( root , minDiff ) NEW_LINE return minDiff [ 0 ] NEW_LINE def postOrder ( root ) : NEW_LINE if ( root == None ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT root . val += postOrder ( root . left ) + postOrder ( root . right ) NEW_LINE return root . val NEW_LINE def preOrder ( root , minDiff ) : NEW_LINE if ( root == None ) : NEW_LINE INDENT return NEW_LINE DEDENT