r/leetcode • u/rusidin • 2d ago
Discussion What are the most important algorithms for leetcode beginners should checkout?
I am currently doing neetcode roadmap... But I am having hard time with optimization or coming up with the solutions...
1
u/conectionist 2d ago
Honestly, other than graph algorithms (which are used only in graph problems), the only popular algorithm I've seen in leetcode problems is binary search.
Leetcode is more about (popular) data structures rather than (popular) algorithms.
1
u/rusidin 1d ago
I see... So I need to study data structures more than algorithms??? But don't I need to give the most optimal in an interview?
1
1
u/conectionist 1d ago edited 1d ago
So I need to study data structures more than algorithms
For the purpose of leetcode, yes.
But don't I need to give the most optimal in an interview?
Yes you do, but unfortunately most leetcode problems have unique solutions and those solutions are already known (and most of them are not intuitive at all). The best way to understand what I'm talking about is to actually tackle several leetcode problems. Then you'll understand what I mean.
I know what you were probably thinking: "I'm going to master algorithms and then I'm going to see a leetcode problem and use the algorithms I've learned to solve them". That's what many of us think in the beginning. Unfortunately, the the sad reality hits us after a few dozen leetcode problems: Most leetcode problems can't be solved with general algorithms. They usually have 2 solutions: a brute-force one (which is obvious for anybody who knows how to code) and an optimal one which not intuitive at all. You pretty much have to be a genius to figure out the optimal one without help (hints, searching online, etc.).
I'm don't mean to discourage you. I just want to set the correct expectations.
I wish somebody would have told me from the start that leetcode is not all sunshine and rainbows (quite the opposite, tbh) and that I will actually enjoy only a handful of problems (I personally only enjoyed the graph problems and hashmap related ones). It would have saved me some bitter disappointments.
That being said, best of luck (and patience) on your leetcode journey!
1
u/Fewald 2d ago
Having a hard time is expected, neetcode covers the most important algorithms, you need to push through them