How you solve the programming problems you’ll be presented with during your interviews will determine whether or not you get a job offer, so it’s important to answer them as correctly and completely as you can. The problems usually get progressively harder as the day progresses, so don’t be surprised if you end up needing an occasional hint from the interviewer. You’ll normally code in a mainstream programming language, but the choice of language is ultimately dictated by the requirements of the job for which you’re applying, so be sure you’re familiar with the right languages.
Interact with your interviewer as much as possible as you attempt each problem. Let him or her know what you’re thinking at each point in your analysis of the problem and your attempts at coding an answer. Start by making sure you understand the problem, and then try some examples to reinforce that understanding. Choose the algorithm and make sure it works for those examples. Don’t forget to test for special cases. If you’re stuck, try more examples and/or choose a different algorithm. Keep obscure or advanced language features in mind when looking for alternate answers.
If asked to comment on the performance of a solution, a big-O run-time analysis is usually sufficient. Algorithms that run in linear or constant time are usually preferred.