|
|
|
|
|
by decafninja
1904 days ago
|
|
Playing devil's advocate, and being on both sides of the interview, I've noticed that a lot of people new to the leetcode interview game see nested loops as deathly evil and desperately try to find some "trick" or "gimmick" algorithm that would let them avoid it. I was guilty of it too. I wasted a lot of interview time trying to spot the nonexistent gimmick when the optimal (or at least good enough) solution was in fact, utilizing a nested loop. If you have a decade of real world experience under your belt, your first instinct would probably be to just write code that uses nested loops and perhaps refactor and optimize as necessary for performance. But now in the leetcode interview game, you're often forced into a situation to prematurely optimize everything to get the "optimal solution" without running out of time. |
|
For the record I always encourage candidates to start with the simplest solution and tell them we can then chat about improvements after we get the basics right.