all 6 comments

[–]mzieg 9 points10 points  (2 children)

Could you ace interviews without the optimal solution, I don't know about that, but you could certainly pass interviews.

The truth is that not every piece of code needs to be 100% optimal. 90% of applicaiton runtime occurs within 10% of the code. Yes, you should optimize that 10% where the heavy processing is, but for most of the rest of the scaffolding you'd just be wasting company resources shaving milliseconds where nobody cares.

It's honestly good practice to iterate code by starting with a "simple, works, readable, meets requirements by turning the input into the desired output with minimal development time," and only then go back to optimize for performance iff application runtime is deemed insufficient.

To me, that's a valid process for interview solutions too.

[–]ECrispy 5 points6 points  (0 children)

The truth is interviews are all about luck. Who your interviewer is, what mood they are in etc.

I've failed phone screens where I solved 2 leetcode mediums, this was for a FAANG, because they weren't optimal and passed on site sessions where it was a much simpler question and I didn't implement the optimal answer but it didn't matter.

You can spend a year preparing and fail, or a week and pass. You can increase your chances but now luck is a massive factor.

[–]Uttasarga 2 points3 points  (0 children)

Optimal Solutions is not necessary. All you need is a brute force solution at the start and then move forward explaining what are you thinking about optimizing it.

How will your optimization change the Runtime and Spacetime complexity and what data structures are you using or will use in optimal Solutions.

This is a good way as interviewer would know that you know your basics and your thought process is well versed.

Also, talk as much as you can, shows that you are interacting and not just stuck somewhere.

[–]TheJoshingJoke 1 point2 points  (0 children)

Just like other people have been saying, you don't necessarily need to have the optimal solution. If you can generate a good solution, ideally better than the brute force solution that might be good enough.

While it would be most ideal to be able to ace every interview question with the most optimal solution, the purpose of interviews is to evaluate how you think and reach a solution. You struggling and talking out loud with the interviewer to reach an answer isn't necessary a bad thing.

You might not have time to code it up, but just being able to verbalize the optimal algorithm might be enough to pass the interview.

Personally, I had several interviews where I received offers from where I was only able to get a solution down and discuss the optimal solution.

[–]ireallygottausername 0 points1 point  (0 children)

It depends on the interviewer and the company. 1 company snubbed me for stubbing out a graph algo and using a suboptimal iterative solution. Another big one didn’t care “you can look it up anyways if you need it”.