Comment by jblow

11 years ago

I have no idea what the job was.

But my point is this is not a bureaucratic gotcha question. If you can't do this task, you don't really know how to program well. Sorry but that's just how it is. It's like failing FizzBuzz.

There is this culture of crappy software that has happened lately, especially in the Web world, and it is really quite lamentable. I believe that a very large positive impact would be made on the world -- due to the extreme prevalence of software these days -- if more people would take seriously the idea of software creation as a craft with a very high skill ceiling, and work diligently to improve their understanding and their skills.

Note that "invert" in this context is fairly ambiguous. I suspect the interviewer meant reverse, which is, I agree, utterly trivial.

I, and apparently many others in this thread, spent some time trying to ferret out an answer to what it would mean to invert a binary tree: at first thought it would imply a collection of nodes all pointing at their parents, which seems not very useful (and would require more than 10 lines of code to whiteboard reasonably).

Much of the discussion is about whether or not the problem was described in sufficient detail or not.

  • The question is definitely not described in sufficient detail. That's usually on purpose. The interviewer WANTS the candidate to realize that too and ask the questions necessary to actually understand what they are trying to solve. It's very analogous to nailing down specifications on a new feature or something like that.

I've never inverted a binary tree (I'm not familiar with the concept). You claim that makes me a bad programmer. Be careful there: just because somebody hasn't been exposed to something doesn't mean they aren't smart enough to figure it out. Fizz buzz is also flawed in this way: it doesn't test if you know how to program, it merely tests "have you been exposed to the modulo operator yet".

  • FizzBuzz is not about the modulo operator. You can write it pretty easily without it, in several different ways. If you can't figure out how pretty quickly, you're not a good programmer. Sorry.

    It is even kind of reasonable to just substitute a call to some black-box is_divisible_by() if you can't figure out how to do that test ...

  • No one is claiming that makes you a bad programmer. However, if you got this as a problem to solve and your response is "I don't know" and you stop there, then you are a bad programmer. As I've commented elsewhere, the interviewers want you to ask clarifying questions. Those are often just as important as the code itself. Once you've nailed down the definition of inverting a binary tree (maybe it's just switching left and right node pointers), coding will be trivial. It's much like getting sufficient detail on a feature request before starting to work on the feature.