Menu

Developer Interview Questions

December 10, 2012 - .NET, C#, Programming

One of the trickiest parts I imagine with hiring a new developer is figuring it out several things about them. One thing you need to figure out is wether they will fit. What I mean is, even the best developer in the world won’t increase a team’s productivity if they don’t mesh well with that team. This means avoiding people that are more likely to force their programming viewpoints on others, or abuse their repo access to “refactor” other peoples code for no distinguishable reason. Additionally, and most obvious- is whether they can actually write code. An astonishing number of applicants to developer positions could not write trivial code in the language they were supposed to know.

The former is why personal interviews- or, if nothing else is possible, a voice communication or phone interview- are used. Though in-person interviews also help determine their personality based on their presentation. The latter- determining whether they are really a developer- is why you often have coding interview questions. I thought I’d look some up and explore them. Why? I dunno.

1.

Given that Pi can be estimated using the function 4 * (1 – 1/3 + 1/5 – 1/7 + …) with more terms giving greater accuracy, write a function that calculates Pi to an accuracy of 5 decimal places.

Now, some developers might end up with something like this:

I rather like the use of the *= directly in an expression. Anyway, this is sort of overthinking it. Look at the question. Like a proof, it provides a given- but, you don’t have to use it Since Pi is a constant, you could just do this:

It does what the function wants- it returns Pi to 5 decimal places. However, it also sort of defies the spirit of asking the question; the purpose is to see if you can use loops and basic control structures. This is more a early screen phase, so those looking to hire can avoid the people who thought “C# Developer” in the ad meant somebody who had expertise building Musical instruments. Even my implementation could easily be improved in any number of ways (not using a int as the for loop variable being one example). But it get’s the point across.

The Clock Angle Problem

Another common question is a tad more involved:

Alright, now we get to some mild brainwork here.It’s interesting because it promotes a bit of thought about the problem. First, you mgiht start by figuring you can just get the angle for the Hour, the angle for the minute, and take the difference:

However, it is not that simple. Consider the following-

1. Look at an analog clock. When it is 9:30, for example, the hour hand is not pointing at the 9. It’s pointing halfway between 9 and 10. So we need to add an angle equal to the percentage the Minute hand is around a full revolution of the distance between two hours.
2. The difference between the 59’th minute and 12AM or 12PM is not one degree from a full revolution as this would show.

The first problem is “solved” by adding the appropriate amount. The second requires a bit of finagling. The final result for me was this:

You can see my comments in there as well; I wrote those before I added the code which they “document”. Now, even this could be argued as being wrong in much the same way as the original version was wrong; the minute hand, like the hour hand, does not “jump” between each minute (depending on the clock); instead the minute hand moves smoothly between the minute markings, based on the second. So in order to be “complete” we’d need to also add in that. But this is much more accurate. The Angle check is perhaps the least obvious part, but is relatively simple and doesn’t require any super advanced trigonometry either.

Have something to say about this post? Comment!