Q: In a coding interview, should I start with the brute force solution or skip it?
This was actually a point of contention among the authors and early reviewers of Beyond Cracking the Coding Interview, with some saying it's not worth the time effort.
I'll give you my answer, but let me know if you disagree.
I lean on YES, but you want to do it quickly. The way we put it in the book, you want to *minimally sketch* the brute force solution in high-level pseudocode, not actually code it.
Why?
- If the problem is confusing, it helps you understand what it is asking, and it gives the interviewer a chance to correct you before you spend too much time thinking about the wrong problem.
- It gives you a baseline for what you need to beat. It can help you identify the bottlenecks, so you know what to focus on.
- It gets the ball rolling in terms of exploring the solution space. Having some early momentum in an interview can make it less intimidating.
But this is not the time to choose the best variable names or work out loop conditions carefully. I talked about how to write pseudocode quickly in this other post:
https://lnkd.in/gJk9Qi5S
This will give you all the benefits without wasting precious time!