10 years ago I was asked how to tell if an integer is divisible by two without using division or modulus. What they expected was to bit mask the 1s place in the integer and check for equality with 0. I'd take Fizzbuzz any day.
10 years ago I was asked how to tell if an integer is divisible by two without using division or modulus. What they expected was to bit mask the 1s place in the integer and check for equality with 0. I'd take Fizzbuzz any day.
Wait, it gets better. I was asked the "divisible by two" question and gave the standard bitmasking technique in response. But then my interviewer said that wasn't "allowed" either, because apparently this programming environment they do their daily work in (this was an old-school web development shop basically) doesn't support basic math operations of any kind except equality, plus and minus.
He then pressed me for something "even simpler", "perhaps using function calls". Then I figured out what the "right" answer was -- he wanted be to test for odd- or even-ness recursively by, well, you know how.
So after reminding him about the obvious performance drawbacks of such an approach, I asked him -- "So do you actually write code like this in production?"
To which his answer was: "No, but I do during interviews".
if CPU masks it then time the read.
ok partly sarcasm but partly: this isn’t a hard question. i’m sure i could enumerate ALL the possible ways to do this. maybe i’m good at puzzles.
if your comment is about how awful an interview question it is, in that case yeah i agree. but not because it’s hard. anyone should be able to answer this.
Further I was pointing out I prefer fizzbuzz because it at least bears a resemblance to what would be done on a daily basis on the job.
> anyone should be able to answer this.
Anyone should be able to answer fizzbuzz yet people who look good on paper constantly fail it. This is why it is useful. And that is why it is actually not a bad interview question. (in my opinion)