You’ll probably encounter a brainteaser or two during the interview process, even if they’re not directly related to your programming skills. Many interviewers use these kinds of problems to see your thought processes at work and determine how well you can think “outside the box.”
Brainteasers come in many different forms, but the obvious answer is almost invariably wrong in all cases. Start by verifying your assumptions to make sure you’re solving the right problem. Don’t be intimidated by the problem - break it into pieces, simplify the problem, and solve specific cases in order to find the general solution. Beware of simple problems, as they’re trickier than they seem. If you don’t have all the facts you need, make reasonable estimates based on prior knowledge and common sense.
No matter what you’re doing, think out loud and explain to the interviewer what you’re doing and the reasoning behind your decisions. Focus on the problem and keep working; it’s your thought processes that count the most here, not the answer itself.