Tips and suggestions
When you get a brain-teaser problem, the most important aspect is to not panic. Read the problem several times and write down your conclusions in a systematic approach. It is mandatory to clearly identify what input, output, and constraints it should obey.
Try to take several examples (input data samples), make some sketches, and keep talking with the interviewer while analyzing the problem. The interviewer doesn't expect you to have the solution immediately, but they are expecting to hear you talking while trying to solve the problem. This way, the interviewer can track the logic of your ideas and understand how you approach the problem.
Also, it is very important to write down any rules or patterns that you noticed while developing the solution. With every statement you write down, you are closer to the solution. Commonly, if you look from the solution perspective (you know the solution), such problems are not extremely hard; they just require a high...