While some candidates don’t prepare at all for coding / algorithms interviews (eek!), others spend so much time preparing that they already know the answers to problems. “Score!” they think. “Now I’ve nailed the question.”
Let’s take a step back. Algorithm questions are designed to test your problem solving skills. When you’re asked, for example, to design an algorithm to find the longest palindrome in a string, your interviewer doesn’t care if you know the answer. Not one tiny bit.
Your interviewer is not testing knowledge, they’re trying to understand how good you are at solving problems you haven’t seen before. They want to understand your problem-solving skills.
If you just spit out the optimal solution to the problem, you’re not giving the interviewer a chance to see your approach. Great, you know the solution, but so what? The interviewer doesn’t care about that. And on top of that, many interviewers will see you as dishonest for not admitting that you know the problem.
Some candidates “wise up” to this and decide instead to pretend to be solving the problem from scratch. They’ll fake struggle for a bit before finding their way to the solution. This is also unwise as it comes with a host of problems:
- You’re basically acting. Are you that good of an actor? Are you sure?
- You’re really deceiving your interviewer. If you get caught, you might get rejected on those grounds alone.
- You might have misheard the problem, or it might be a slightly different problem than you’d heard before. Your struggling could be making you look a lot worse than you are.
- Your interviewer has probably seen dozens of candidates solve this exact question before. She knows exactly what a “normal” path is, and what good performance looks like. You, however, do not. You’ve previously solved it once, if that (you might have just read the solution before). You don’t know what “good performance” looks like – so how can you act like a good performer on this problem? You’ll likely get caught – or wind up struggling more than a good candidate would.
- Even if you’re not caught on that problem, what have you really shown? Your interviewer will just go on to a new problem – one that you probably haven’t heard before – and then your weaker performance here will make your interviewer suspicious of your “strong” performance earlier.
“Fake struggling” ends up hurting your performance more than it helps you. Don’t bother.
On the other hand, if you tell your interviewer that you know the problem, he’ll just move on to a new question (or potentially ask you to solve it anyway). You’ll probably get some “bonus points” for your honesty too.
Also, it should be said: It’s just the right thing to do. Pretending to solve a question that you’ve heard before just isn’t particularly ethical. Don’t you want to do the right thing and the smart thing?