Meta | Phone Screen | Enterprise Engineer | Reverse Polish and Postorder tree traversal
Anonymous User
426

Paying community tax.

1.https://leetcode.com/problems/evaluate-reverse-polish-notation/
2.https://leetcode.com/problems/binary-tree-postorder-traversal/

I solve 1 in 10 minutes with a stack.
I choked on # 2 because I for some reason want to put everything in to a stack then print out the result.
this is what I was going for

public void postorder(TreeNode root,Stack<Integer> output){
        if(root == null){
            return;
        }
        postorder(root.left, output);
        postorder(root.right, output);
        output.push(root.val);
    }

but I had this and I see the obvious problem, but couldn't figure out how to fix it. Struggled for about 15-20 minutes before time ran out.

public void postorder(TreeNode root,Stack<Integer> output){
        if(root == null){
            return;
        }
		output.push(root.val);
        postorder(root.left, output);
        postorder(root.right, output);
    }

Solved a medium and was sitting on the answer for easy. Hopefully they'll give me a chance :*(

Comments (1)