Need a hint?
a null tree has length 0. Use this fact to eliminate null checks.

Pages: 1 2 3

2 Responses to “Scohen’s interview question”

  1. Steve, not Cohen Says:

    I feel all special cause I came up with your boss’s answer. But, I don’t think it’s all that hard of a problem. I guess a CS background leads you to think about recursion whenever you think about trees, so maybe the classically trained programmers have an advantage over the rest of coding humanity. But, still, anyone who’s done any XML work has probably had to do some recursive tree walking, so a mid-level IT-ish dev ought to have no issue recognizing the solution. I may start asking this at interviews–I’m getting bored with asking people to write a ‘for’ loop.

  2. steve cohen Says:

    Yeah, maybe it’s not too hard for non CS people, but I really don’t think an incurious person would get it, even if they did XML. They’d probably do loops or use Xpath.
    ..and don’t forget how many people fail your for loop test.
    By the way, comments don’t appear until I approve them, otherwise, I get spam.

Leave a Reply