public static TreeNode postorderSuccessor(TreeNode n) {
        // case 1: n is the last node in traversal ->
        //         return root's parent, ie., null
        if (n == null || n.parent == null) return null;
        // case 2:   n is left child of its parent ->
        //           just return parent
        // case 3:   n is right child of its parent
        // case 3.1: parent has no right child ->
        //           just return parent
        if (n.parent.right == n || n.parent.right == null) return n.parent;
        // case 3.2: parent has right child ->
        //           return leftmost bottom node of parent's right subtree
        return leftmostBottomChild(n.parent.right);
    }