Don’t Be That Guy

So we interviewed someone today for a developer position. I gave him a simple weeding out question, one that I explicitly told him was just for that purpose. The question was: given an integer greater than zero, write a function to determine if it’s a power of 2. I also told him I didn’t care about language/syntax, that he could use pseudocode. First of all, this guy hemmed and hawed and without even trying, said that he was tired, hadn’t gotten a lot of sleep, and gave up saying he didn’t know binary math. We prodded at him. Finally he made an attempt after I said “well, why don’t you take an example like 64 and see how to make it work?” He eventually came up with a mediocre but functional answer using a while loop and a break. As a followup, I asked him to do it with a recursive function. He couldn’t make it work, saying it was “tricky”; he just kept writing more and more complex code.

But he seemed to have a good attitude and was willing to learn, etc so while I wasn’t impressed, I was willing to attribute it to nerves and see how he performed in the more technical part of the interview. He did poorly there and that was that. But here’s the kicker… His last interview was with two of our product managers. He evidently told them that questions like the one I asked him don’t accurately represent a candidate’s skills, and why would he ever need to find out if a number is a power of 2. Are you kidding? Really? Who the hell 1) doesn’t understand the purpose of basic algorithm questions 2) tells someone else in the interview process that you think the question is bad?

BTW, the power of 2 question is one that I made myself solve the first time I heard it without reading an answer to see if it’s a fair question to ask. So yes, I do know how simple it is to solve; it took me about 30 seconds to get the approach and another minute or two to prettify for consumption. Just one recursive sample is below.

function isPowerOfTwo($number) {
  // If the number is odd, it's not a power of two, we can short-circuit
  if ($number % 2) {
    return FALSE;

  if ($number > 2) {
    return isPowerOfTwo($number/2);
  return ! (bool) ($number % 2);