In case you missed it, I did at least, here is John McCain at the Al Smith dinner.
Also, in xkcd today, they came really close to getting Kayleen down. Her morning routine is 1, 3, 2.

Also, Ryan got the riddle correct. The way I answered was basically the same, but I wasted more power by turning on two lights, waiting some amount of time then turning one off.
I had a phone interview with a company yesterday and they asked me this question, let's say you have an array of n numbers. In the array of numbers, you have all the numbers from 1 to n-1 in the array plus one number is repeated. How would you find the number that is repeated? An example of what an array of numbers would look like, if you had an array of 10, the array could look like this.
[1, 6, 3, 2, 4, 7, 8, 9, 5, 2]
So the answer here would be two.
3 comments:
I would use some sort of algorithm. But the key is to use a GOOD algorithm. Some people try to find repeated numbers using crappy algorithms, and those NEVER work.
You are supposed to give an idea of your algorithm. Actually, the way the guy I talked to did it didn't use a searching algorithm. Since you know that you have the numbers from 1 to (n-1), you can use that knowledge. You use the math algorithm that tells you the sum from 1 to (n-1) and then you go through your array and add up all of the numbers. You then take that number minus the sum of 1 to (n-1) and you'll have your answer.
Duh. Like i already said: use a GOOD algorithm.
Post a Comment