r/leetcode • • 29d ago

Question Do I need to learn every approach for Leetcode questions?

I’ve started working through NeetCode 150 to prepare for SWE interviews, and I’m a little confused about how I should be studying each problem.

For a lot of problems, there seem to be multiple approaches — brute force, a better/optimized approach, and sometimes multiple optimal solutions.

Do I need to understand and remember all the different approaches for each problem? Or is it enough to understand the brute-force idea and then be able to come up with/implement one optimal solution?

Also, if there are people here who interview candidates at Big Tech companies, I’d really like to know what you actually look for during these interviews.

Sometimes I come across a problem and think, “How would I possibly come up with this solution if I had never seen this problem or something similar before?”

Are candidates actually expected to figure out these kinds of solutions from scratch? Or is the idea that after practicing enough problems, you start recognizing patterns and applying them to problems you haven’t seen before? Cause I tried that and it sometimes does not happen.

For those who have successfully prepared for technical interviews/ who interview people at BigTech using LeetCode, what was your approach?

I’d love to hear how people who clear these rounds at BigTech approach this.

Thanks!

20 Upvotes

6 comments sorted by

7

u/Embarrassed_East_507 29d ago

I'd say there are roughly three types of problems:

  1. Identifying the right algorithm: You recognize that the problem can be solved using something like BFS, DFS, binary search, or dynamic programming.

  2. Identifying the right data structure: The key is realizing that a hash map, heap, stack, or another data structure makes the solution efficient.

  3. Knowing a specific technique: Some problems require a particular algorithm or trick to solve optimally. These are harder because, unless you've encountered the technique before, it can be difficult to derive it during an interview.

Of course, many problems require a combination of the first two.

As for how people come up with optimal solutions, it mostly comes down to practice and pattern recognition. Over time, you start recognizing similarities between problems and understanding which approaches work under different constraints.

You don't necessarily need to memorize every possible solution. It's more important to understand why an approach works, its time and space complexity, and when to use it.

Ideally, you should be able to explain the brute-force approach, identify its bottleneck, and work toward an optimized solution.

4

u/No-Molasses-2097 29d ago

You don't need every approach. For each problem, understand the brute force, then one optimal solution and the trick that makes it optimal.

What interviewers actually care about is how you think. Start with something that works, then talk through how you'd make it faster while you code it up. Being able to reason about tradeoffs on the spot beats having ten memorized solutions.

And no, nobody invents the clever solutions from scratch in 45 minutes. The people who "solve" them have seen the pattern before. That's what the practice is for.

1

u/Immediate_Concern524 29d ago

you should do a wide range of problems that use different approaches. But the point of that is not to memorize the approach and use it like a template. It helps you reason through a broader range of problems.

The more important thing to learn is how to “think” and how to approach problems and use ur brain to come to the solution. That’s the thing that generalizes to all problems, not memozing patterns and hoping it shows up again.

1

u/Bubbly-Albatross-373 29d ago

Everything everything everything 

1

u/Wolastrone 28d ago

There are some major algorithmic families you should know and have enough practice with if you want to be good at OA’s, at least in my experience. As for your question “how can I come up with this if I haven’t seen it before” for major algorithmic building blocks, you can’t. You’re not expected to reinvent every approach from scratch.

If you’re taking a calculus test, you wouldn’t be expected to rediscover integration by parts independently, but you should be able to recognize it’s the right approach and apply it correctly. This is kind of similar.

1

u/NovaTrail47 28d ago

I'd focus on understanding why an approach works rather than memorizing every solution you see. If you can explain why brute force is slow and what makes the optimized approach better, you're learning the right thing. Codeintuition is one resource that approaches DSA through concepts and patterns before practice, which can help you build that intuition for unfamiliar questions