I Don't Want to Hire You If You Can't Reverse a Binary Tree
61–70 of 115 posts
Re: I Don't Want to Hire You If You Can't Reverse a Binary Tree
#62It's not a "brain teaser" or a "trick question". It's an ordinary software engineering problem.
Doing it on a computer is more along the lines of a software engineering problem, though still it is largely academic and counter to one of the tenets of good software engineering (that all code is a liability, and thus new/non battle tested code should be avoided whenever possible).
Re: I Don't Want to Hire You If You Can't Reverse a Binary Tree
#63Sigh. If you hire using know it or not questions about binary trees, then you finally get to hire people who can study up and answer that specific question in a manner Pavlov would approve of. That does not mean the candidate will be able to design clean APIs, know how best work with different types of data, or even how to troubleshoot existing code. Still, pat yourself on the back, I mean, your entire team can answe…
Re: I Don't Want to Hire You If You Can't Reverse a Binary Tree
#64Sigh. If you hire using know it or not questions about binary trees, then you finally get to hire people who can study up and answer that specific question in a manner Pavlov would approve of. That does not mean the candidate will be able to design clean APIs, know how best work with different types of data, or even how to troubleshoot existing code. Still, pat yourself on the back, I mean, your entire team can answe…
How is that a "trick" question? I never been asked that in an interview question and had the correct solution in my head in just a few seconds for the very reason he gives -- experienced programmers can map their intuition to code. This is certainly a skill that takes time to develop, and if you're concerned with hiring the best, don't you think this is a decent heuristic to throw in with a bunch of others ? Programm…
Perhaps instead of being annoyed, you could try to understand why people are sighing. Many of them will have lost out on a job they were qualified to do because of bullshit interviewing practices like this one. It has a real effect on them. It's not a trivial issue.
> You don't have it all figured out.
No one here has claimed to have it all figured out, nor are the majority of comments an implication of that. We're all just saying we have one thing figured out: whiteboard interviews are terrible, alienating, unrealistic, antiquated tools for hiring.
Your profile says you're a CTO, and you should know that research increasingly shows that people don't quit jobs, they quit bosses. If you want to be the kind of boss that programmers want to work for, you should be more open to understanding why the vast majority of us feel strongly about a topic like this instead of calling us obnoxious.
If you yourself are not a programmer, I'm not sure why you're weighing in on this at all.
Re: I Don't Want to Hire You If You Can't Reverse a Binary Tree
#65I don't know JavaScript (maybe it somehow handles this automagically) but isn't his reverse function missing the base case of a NULL tree? function reverse(t) { var tmp = t.left; t.left = reverse(t.right); t.right = reverse(tmp); return t; }
Re: I Don't Want to Hire You If You Can't Reverse a Binary Tree
#66Couldn't disagree more with the author. How many developers need to implement their own binary-tree? This is why code-bases become convoluted with six different implementations of standard data structures.
Well, to pick on Valeri, this is simply wrong Trees are the single most important data structure in computer science. Just about everything you do in your programming career will be related to trees. Trees are a horrid data structure for any modern processor. Pointer chasing thrashes caches. The actual most important data structure is a hashmap. The same speed in theory, much faster in practice.
Re: I Don't Want to Hire You If You Can't Reverse a Binary Tree
#67The other thing is that knowing a tree is symmetric and know how to reverse one don't count as new and unknown challenges that author mentions. Both are well documented and easily accessible to anyone who needs to know that information.
I recently had an interview where I was presented with a problem the company had to solve. That was new and exciting, not some minor detail from CS100 I learned years ago.
Re: I Don't Want to Hire You If You Can't Reverse a Binary Tree
#68It's not a "brain teaser" or a "trick question". It's an ordinary software engineering problem.
Doing it on a whiteboard is an academic computer science problem. Doing it on a computer is more along the lines of a software engineering problem, though still it is largely academic and counter to one of the tenets of good software engineering (that all code is a liability, and thus new/non battle tested code should be avoided whenever possible).
Re: I Don't Want to Hire You If You Can't Reverse a Binary Tree
#69Sigh. If you hire using know it or not questions about binary trees, then you finally get to hire people who can study up and answer that specific question in a manner Pavlov would approve of. That does not mean the candidate will be able to design clean APIs, know how best work with different types of data, or even how to troubleshoot existing code. Still, pat yourself on the back, I mean, your entire team can answe…
In the first approach he gives, you need to divide the problem into smaller subproblems, knowing that a tree is the combination of either two branches that are themselves trees or a single leaf node. What's the rule for determining whether two trees are symmetric? Well, if both of them are leaves, the answer is trivially true. If one of them is a leaf and the other is a branch, the answer is trivially false. If they are both branches, then you need to make sure that the left branch matches the reversed copy of the right branch, and vice versa, i.e. left is symmetric to right and right is symmetric to left. And you have the solution he gave.
That also clues you in to the second solution, where you define "symmetric" as "the reverse of tree1 is equal to tree2", and then write appropriate recursive helper functions for this.
What the author's really testing for is "Can you decompose problems that you don't know how to do into problems that you do know how to do?" This is a critical skill for doing anything new, and the vast majority of economic gains in the software industry go to people producing new stuff and not looking up other peoples' solutions. Effectively, what he's trying to select for is folks who don't believe this is a matter of received wisdom and instead are willing to figure it out themselves.
(Interestingly, there's a bug in his code. It doesn't affect the correctness of the point he's trying to make, but would be infuriating to an actual Javascript programmer working with this function. See if you can spot it before he merges my pull request...)
Re: I Don't Want to Hire You If You Can't Reverse a Binary Tree
#70The problem with the question is that it's an intellectual circle-jerk. "Do you know what this fancy term is that nobody uses in their day-to-day life?". "Oh, you don't know? Haha, stupid peasant".
Instead of asking these gotcha questions, why not ask something practical that does the same thing? "Given a complex user model with multiple relationships, how can you map the relationships? Or something like that.