Interlost

It seems more in this day and age of "current year" that we've lost the reason interviews exist. Not to those doing them, but to those attending them. This isn't something I normally think about, being stuck in my own world most of the time, but my interest was peaked when someone sent me rejected.us. I read down a little bit, to find it was a pity party for those rejected jobs from interviews. I can't relate to these types of things anyway, it just seems to be people in good places generating themselves issues. One post that really bugs me is the creator of Homebrew's infamous post about him being rejected a job at google for failing to invert a BST.

That's where I got a little angry.

This isn't someone I had really done before, so could I really say anything? After a few minutes of dumb deliberation, I tried it myself. It took me about twenty minutes, not really paying attention that hard.

    TreeNode* invertTree(TreeNode* root) {
if(!root)
return NULL;
invertTree(root->left);
invertTree(root->right);
TreeNode* t = root->left;
root->left = root->right;
root->right = t;
return root;
}

10 lines.

It surprises me how anyone could fail this. I'm not some CS genius or anything, just some random kid in high school with a little too much free time. It's a classic example of recursion, going along the left and right branches of the BST and flipping them before returning to the base case to swap them on the root node, it's something I can almost visualize in my head. Maybe I'm just hopeless and don't want the system to change, but I don't think companies are going to give up anytime soon on testing you with basic data structures.

So please, learn your data structures.