void go(TreeNode root){
        if(root==null)return;
        go(root.left);
        go(root.right);

        int leftSum=sums.getOrDefault(root.left, 0);
        int rightSum=sums.getOrDefault(root.right, 0);
        sums.put(root, leftSum + rightSum + root.val);
        tilts.put(root, Math.abs(leftSum-rightSum));
        sum+=tilts.get(root);
    }
Do post-order traversal and keep track of value sums of each node.
src/problems/easy/BinaryTreeTIlt.java