October 2008 - Posts

Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.

----

We don't actually need a computer to solve this problem, but why not?

 

The formula for the sum of the squares of the first n natural numbers is:  n*(n+1)*(2n+1)/6 .

The formula for the sum of the first n natural numbers is:  n(n+1)/2 .

 

We can write this in ruby:

 

def sumToN(n)

   (n*(n+1))/2

end

 

def sumOfSquares(n)

  (n*(n+1)*(2*n+1))/6

end

 

puts sumToN(100)**2 - sumOfSquares(100)

 

Note that you don't need an explicit return statement.  The last expression in any function will be returned by default.

Posted by mfedner | with no comments
Filed under: ,

Every interview is difficult, because on both sides, you know you're about to make an important decision based on very little information.  But it seems to me that interviewing a recent college grad can be especially difficult for an industry veteran.  There typically isn't much to say about the candidate's past software experience or framework knowledge, so the interviewer is left evaluating the candidate only on intelligence and personal qualities, rather than on real-world software development competence.  So what are the most useful questions to ask in this scenario? 

Here are some of the memorable questions I've been asked in interviews for an intern or junior software developer role: the good, the bad, and the ugly. 

 

Q: A Microsoft puzzle, such as: How many gas stations are there in the USA?, or How many golf balls fit into a school bus?

My verdict: Bad. If the candidate doesn't display her cluelessness by being flabbergasted, how exactly do you judge the creativity or accuracy of her reasoning?

 

Q: Write a function to reverse a string.

My verdict: Good.  Discussing solutions that optimize for space or speed can show a candidate's understanding of the basics (or lack thereof).

 

Q: There is a room with a door (closed) and three light bulbs. Outside the room there are three switches, connected to the bulbs. You may manipulate the switches as you wish, but once you open the door you can't change them. Identify each switch with its bulb.

My verdict: Bad.  Either the candidate has heard this question before, or he hasn't.  Even the unlikely case where he comes up with the solution on the spot doesn't tell you much about his prowess with a compiler or a customer.

 

Q: Does object-oriented Square extend Rectangle?

My verdict: Good.  What does resize(3,5) do to a Square : Rectangle?   If a brand-new developer can see this pitfall to the naive approach to object-oriented design from CS 101, that's pretty good.

 

Q: The typical HR-type questions: What is your weakness; Where do you want to be in five years?

My verdict: Ugly.  Unless the candidate, instead of reciting the typical canned answer, admits a fondness for underage girls, or his plan to take over your business and become your boss. 

 

Q: Design an elevator system for a 100-story office building.

My verdict: Good. Opens the discussion to technical and UI factors, and  lets you assess your candidate's creative and problem solving skills.  Can he see the big picture?

 

Next time: more ideas for effectively interviewing entry-level developers.

Posted by mfedner | 752 comment(s)
Filed under: ,