Hacker News new | ask | show | jobs
by dmitrygr 2522 days ago
Phone screens at google are not foolproof, and some candidates get to skip them for various reasons. I've seem some candidates make it to onsite and then be unable to answer my warmup question of: write a function that takes an integer, leaves all the zero bits alone, changes all the one bits into zero bits, and returns the result.
2 comments

How is a disguised return 0 anything remotely resembling a good question? I highly suspect most people who are "unable to answer" are actually just misunderstanding the question, since it's phrased in such a bizarre way. The way you phrased it, I'm not even 100% sure that "return 0" is the answer you're looking for!
It is a warm up meant to take 20 seconds. Before we get to something actually meaningful
That’s the right return value of course but ignoring everything else doesn’t actually meet the requirements of the question. Of course in a live situation you can ask if that’s ok or if they actually want useless bit twiddling.
But there's no such thing, semantically, as "leaving zero bits alone". The value 0 has no notion of "where it came from". The expression "x & 0" is semantically equivalent to the expression "0", in that they represent the same value.

In my view, the fact that the question even lends itself to philosophical debate like this just illustrates how exceptionally bad the question is, even by Google standards.

Oh I don’t disagree. Literally going through bit by bit and zeroing any bit not equal to zero would be grossly inefficient especially if you know it’s unnecessary.
It's not grossly inefficient to do 64 iterations of an arithmetic loop for a trick toy function that has no reason to ever be called in practice.
As far as I understood the document Google could have argued to have individual members of the class action dismissed based on qualifications after discovery concluded. The "in person interview" was just the initial requirement to join the class action and not a guarantee that they would remain part of it. The article I linked already mentioned 269 and that dropped to 227 in the bloomberg article linked by the guardian, so around a sixt no longer qualified for one reason or the other.

> leaves all the zero bits alone, changes all the one bits into zero bits, and returns the result.

Unless you have a weird integer implementation there is no way to avoid touching individual bits. So if( x ) x = 0; return x; is the best I can come up with.

The best answer is just return 0
With the 20 second duration you mention in a different comment that makes more sense. I think I spend more time just overthinking on the requirments.