The common advice you'll see is "Tell the interviewer so you can get a new question"
I disagree.
You should take every advantage you can get. The whole point of studying ahead of time is to prepare yourself for the inevitable interview question, if you've seen it before you are likely in a really good place to answer it well.
My take on what to do if you've seen a question before
* Don't get overly excited, if you let out an audible "YES I know this one", the interviewer may give you a different problem.
* A lot of the time you think you've seen a problem before but you really haven't. When you get overly confident and then realize you haven't seen it, it looks really bad. Don't introduce that opportunity to get hit
* If an interviewer asks you "Have you seen this one before?" you should say, "I don't think so!". Why? Because it's the truth, you probably haven't. A lot of the times you've seen a similar problem, one small tweak can result in a very different solution. You should be cautious!
* You want to be sure you walk your interviewer through your thinking even if you know the right solution out of the gate. Spend time analyzing the problem, really quickly coming up with a brute force solution, and then showing how you can optimize it to the real solution. This will show a clear line of thinking which is what the interviewer is looking for. As long as you have structure in how you solve interview problems you shouldn't have an issue. Here was my structure: https://docs.google.com/spreadsheets/d/1gy9cmPwNhZvola7kqnfY3DElk7PYrz2ARpaCODTp8Go/edit#gid=0
Tldr; I firmly believe you shouldn't throw away any advantage you have
For example, people who have seen the problem before will sometimes more or less remember the solution but not how they got there. Then the interviewer asks some questions about the solution which they really don't know how to answer and that looks bad.
> You want to be sure you walk your interviewer through your thinking even if you know the right solution out of the gate. Spend time analyzing the problem, really quickly coming up with a brute force solution, and then showing how you can optimize it to the real solution. This will show a clear line of thinking which is what the interviewer is looking for. As long as you have structure in how you solve interview problems you shouldn't have an issue.
This is the key point. Interviewers aren't looking for you to get the right answer, they are looking at how you think about the problem, how you communicate your solution, and what trade offs you make. If you just blurt out the correct answer without context, you probably haven't demonstrated the things they are looking for.