|
General C++ Java Interview Questions Article by Orson Scott Card |
Programmer Interview QuestionsTal Moshaiov’s QuestionTal contributed this question after seeing the others I had posted here. He is a team leader from Israel that was (is?) looking for questions for Java programmer interviewees. A man dies and arrives to the gates of the next world. He sees 2 gates. One of the gates leads to Heaven and one to Hell, however they’re unmarked. At each door stands a guard. We know that the guard to Hell always lies and that the guard to Heaven always tells the truth. The man is granted with one question to ask one of the guards to figure which gate should he enter. What is the proper question? SolutionBackAnother Microsoft QuestionYou have one gold bar that you are going to use to pay a guy who works for you. You must pay him daily, so the gold bar has grooves to be split 6 times (making 7 pieces). Imagine it is kind of like a Kit Kat® bar. You can only break the gold bar TWICE. How do you break it twice and still manage to pay him for each day’s work? SolutionBackWestwood Studios (April 1999)This test is what Westwood Studios faxes you if you request to interview for a programmer position. It is by far the most draconian programmer test I’ve come across. Most of the questions in it I could answer per their instructions. Some of them just make me think, when am I ever going to have to do this without referrence material and tools (like a calculator)? This test was designed to determine speed, accuracy, and general problem solving abilities. When answering these questions, try to complete each problem swiftly and accurately. You may not use any reference materials nor a calculator, so please show all of your work.
Mike Reed’s QuestionAssume you have eight (8) balls. The balls are identical in appearance (shape, size and color). All balls are also identical in weight except for one (1), which is slightly heavier than the other seven (7). If all you have to measure the balls is a balance, what is the fewest number of comparisons you can make to find the heavier ball? SolutionBackJosh Jensen’s QuestionYou need to reverse the order of bits in an 8-bit element (a byte). For example: 11001110
would convert to: 01110011
What is the absolute fastest way to find the reversed order any 8-bit byte? SolutionBackGary Strawn’s QuestionGary doesn’t use this question anymore. It only applies to the old x86 processors. The new processors use multiple pipelines and this would not actually be the fastest method for such a processor. But I still like this question anyway. One just has to remember that it only applies to the older-type processors. Suppose you need to swap the values stored in two registers. Assuming the processor does not have a swap command, what is the fastest way to transpose the values in the two registers? SolutionBackMike Moore’s QuestionYou have two lengths of rope. Both ropes take exactly sixty (60) seconds to burn. But the speed at which they will burn varies along their lengths. The sections at which they vary are different for each length. The portions where the ropes burn fast and slow are not given. Despite the varying speed at which they burn, they both burn for exactly sixty (60) seconds before they are totally consumed. Using nothing but the ropes, a lighter and a vessel of water (to extinguish the ropes) how can you determine when exactly fifteen (15) seconds has elapsed? SolutionBackThe Classic Microsoft QuestionWhy are manholes round? SolutionBackBonus QuestionHere’s another question I got from Mike Reed or Mike Moore or perhaps even someone else—I don’t rightly remember who it was. Suppose you have a round cake. It has a square portion cut from it. You must divide it into two equal portions. What is the proper way to do this with only one cut? SolutionBackDarren Eggett’s QuestionYou have 3 light switches in one room and 3 incandescent light bulbs in another room. What’s the fewest number of trips between rooms you can make to determine which switch controls which light? SolutionBackEmail me your programmer interview questions! |