I Don't Want to Hire You If You Can't Reverse a Binary Tree (2016)thecodebarbarian.com 3 pointsPosibyte8 years ago2 commentsSaveHideCopy link On HNComments−kwillets8yJust traverse the tree forwards and backwards simultaneously and match the moves. I hate peevish interviewers. If you want to show off, write a paper. bool is_mirror(left_tree,right_tree) { if( !left_tree && !right_tree) return true; if( !left_tree || !right_tree) return false; return is_mirror(left_tree->left, right_tree->right) && is_mirror(left_tree->right, right_tree->left); } bool is_symmetric(tree) { !tree || is_mirror(tree-left,tree->right); }−coreyp_18yI don't think this hiring methodology is good. Just look at all of the negative comments on the post itself! Many of them make good points.
Comments
Just traverse the tree forwards and backwards simultaneously and match the moves. I hate peevish interviewers. If you want to show off, write a paper.
I don't think this hiring methodology is good. Just look at all of the negative comments on the post itself! Many of them make good points.