Pages

Sunday, May 29, 2011

Puzzle/Brain-Teaser Interview Questions

I came upon an article (here) on Techcrunch about CS recruiting. There's this quote in it:

Like many of the hangovers that haunt modern software engineering, this is ultimately mostly Microsoft’s fault.2 Back when they were the evil empire where everyone secretly wanted to work, they were famous for their “brain-teaser” interview questions – Why are manhole covers round? – and, of course, they asked new university graduates about computer science theory; “Write me a binary search."

I remember reading a similar comment/article on theDailyWTF (here).

Although I personally don't like to give these kinds of questions in interviews, I personally do not think the brain-teaser questions are as bad as most people think they are. What they are is bad if executed improperly. I think most interviewers, at Microsoft or otherwise, do not know how to execute the question, the interview and judge the answers from candidates. Some examples:

A) Many interviewers want the right answer from the candidate, and will reject a candidate if they can't solve it. This is the wrong attitude. The question is trying to judge how a candidate thinks through a problem to solve it. Even arriving at the wrong answer is acceptable if the plan of attack was acceptable.

B) The question is also meant to judge your communication ability. Can you talk about how you model the problem, or want to plan to attack the problem, etc. Compared to normal programming questions, you have to speak out of your element.

C) The question also judges your ability to work under pressure and/or show your willingness to not give up. Some candidates may (do?) break down in interviews. Is this the type of employee that will break down in front of a client, partner, or co-workers if presented something difficult or stressful?

D) The brain-teaser/puzzle questions should be given along with other normal technical questions and behavioral questions. It's shouldn't only be brain-teaser/puzzle questions. I interviewed with a company straight out of college that gave me around 10 C programming "puzzle" questions. I probably got 6-7 right, which was enough for them to understand that I really knew C well and got to the next round of interviews. I've known of other people that have been given ONE C puzzle question, and that one question determined if they knew C well enough or not for the job. It's a good example of how not to balance the interview.

Update (12/6/11)

One additional thought. There are also good puzzle/brain-teaser questions and bad ones. Some, such as "Why is a manhole cover round?", are terrible questions. There is little ability to get the candidate to think through the problem and reason it out. A question such as, "How many golfballs can you fit inside a school bus?" isn't that bad.

Wednesday, May 25, 2011

Definition of Poll

So I was talking with a colleague the other day about my initial confusion over the function ibv_poll_cq() in Infiniband verbs. I initially thought/assumed that the function operated similarly to the poll() syscall and was a tad confused on where/how a timeout could be specified to ibv_poll_cq(). As I worked through things, I later realized the ibv_poll_cq() does not iterate, sleep, or wait for an event to occur. It returns immediately if any events are ready or not. It's similar in action to poll() with a timeout of 0.

My colleague and I then got into a discussion of the definition of "poll". My colleague comes from a bit more of a hardware background and considered "poll" to mean a singular check of a state (such as in a register). I on the other hand, perhaps coming from more of a generic systems background, had always considered "poll" to imply both the check of state and some waiting system with it (may it be via sleep, busy-wait, etc.). I asked my colleague how he would say he wants to check a state multiple times? He said, "That's a poll loop."

Another way to think of it, is suppose I had some generic function like:

poll_for_event()

Would the initial assumption be that this function blocks or does not block?

So I was curious about the definition and how it is used in the broader community. I started with an assumption that the term "poll" in Computer Science comes from "poll" in relation to voting. According to Websters the definition of poll is:
"a sampling or collection of opinions on a subject, taken from either a selected or a random group of persons, as for the purpose of analysis."
The question is, can "poll" be applied to a single individual or must it be applied to a group? For example, can you say, "I want to poll a person about this vote?" Naturally, I have no background in linguistics or philology, so I'm just going on a guess here. When speaking of "poll" and voting, I think it is synonymous with gathering the opinions of multiple people and the singular case makes no sense. Otherwise, a "poll" accomplishes nothing towards determing majority vote/opinion. So in my opinion, this might lend the definition of "poll" to include the waiting/loop/whatever instead of a single status check.

Now, "poll" can be twisted when moved into a different field (such as a "bug"). When I initially thought of the syscall poll(), I was thinking predominantly about how it returns to the user after a specified timeout and returns event statuses. However, perhaps it is not named "poll" for this reason. Perhaps it is named "poll" due to its management of multiple file descriptors. In some respect, poll() gathers the "opinions" of each of the file descriptors and records them. So it sort of matches the classic voting definition of poll above.

But this doesn't help our discussion. Lets go back to the case where we're talking about "polling" a state or status. Wikipedia says:
"Polling, or polled operation, in computer science, refers to actively sampling the status of an external device by a client program as a synchronous activity."
and
"Polling is sometimes used synonymously with busy-wait polling (busy waiting)."
Here, it is implied that "poll" implies active multiple-checking and not a singular check of a status. However, I notice that in the above definitions from Wikipedia it is "polling" and "polled", but not "poll". In fact, as I look around the web, virtually every definition or description of "polling" in reference to this topic is listed as "polling". With rare occasion is this topic discussed using "poll" or "to poll" or "polls" (discounting the situations where it appears people are referencing poll() specifically).

So does "poll" refer to a singular check or an active sampling? In all liklihood different niches of the technical community eventually came up with their own definitions/meanings. It's one of those funny things that just happens (Perhaps I'll write someday of the confusion I've had with colleagues over magic numbers). I bet it comes down to common programming scenarios and expectations. Lets go back to my imaginary function:

poll_for_event()

In some communities, such as network programmers or GUI programmers, the assumption might be that the function blocks. The reasoning is simple. Under most circumstances, there's not much to do until the function returns (e.g. http request arrives, GUI item is clicked). So a person in this community who says, "poll", you are likely to believe that you wait until an event occurs.

Then perhaps you have people in the kernel community, where you have many other things you would rather be doing if an event isn't ready. So the natural assumption is the function won't block.

Tuesday, May 3, 2011

What is wrong with Albert Pujols?

Everyone that knows me knows I love Albert Pujols. He's the greatest baseball player of his generation and he plays for the St. Louis Cardinals. But what is wrong with him? Is he just in a prolonged slump? Look at these numbers through May 2nd.

.241 BA, .310 OBP, .438 SLG, .747 OPS

Compare to his career average of:

.330 BA, .424 OBP, .621 SLG, 1.045 OPS

I know in 2007, he started off the season very slowly hitting:

.250 BA, .343 OBP, .489 SLG, .832 OPS

but this is ridiculous. Is the pressure of his free agent year getting to him? If you take out the first 10 games of the season, where he was just awful, Albert Pujols is hitting:

.291 BA, .358 OBP, .500 SLG, .858 OPS

which is more reasonable. I suppose even the greatest players of all time will have slumps, look at what happened to Frank Thomas in 1998:

.265 BA, .381 OBP, .480 SLG, .861

This was after he hit:

.330 BA, .452 OBP, .600 SLG, 1.053 OPS

from 1990 to 1997.

I can only assume it's a slump, and it happens. If he wasn't hitting any home runs or getting any hits, then I suppose it'd be more concerning. But it appears even Albert Pujols can have a bit of a down year.

Update:

This blog entry (via Rob Neyer, via this post) suggests that Albert Pujols was injured and not letting on that he was injured. It's a good argument.

After 27 games without a home run (and hitting only a measly 4 doubles, seeing his slugging percentage drop from .512 to .409), Albert Pujols hit a home run on May 23. And then he hit 4 home runs between May 30th and June 4th. It's looking like that hamstring injury is all healed up.