How I Mastered Data Structures and Algorithms for ML (In 6 Weeks)

Editor
11 Min Read


, I’ve passed over 90% of coding interviews, and it’s not because I am some sort of genius.

The majority of coding interviews in the data science and machine learning space are either on LeetCode or HackerRank, typically asking a data structures and algorithms question or something closely related.

And what I have discovered over the last couple of years is that you can “gamify” your prep for these interviews through certain strategies and by practising specific questions.

So, in this article, I want to break down exactly the process I went through to master coding/data structures and algorithm interviews in just 6 weeks.

Let’s get into it!

Stop Learning Data Structures & Algorithms

The first step may seem counterintuitive, but it’s to actually stop trying to learn data structures and algorithms the traditional way.

For those of you unfamiliar with data structures and algorithms, or DSA for short, let me give you a quick definition of these terms:

  • Data structures — Organising and storing data so it can be accessed and modified efficiently.
  • Algorithms — Step-by-step procedures or sets of rules for solving a problem or performing a task.

Together, DSA is the study of how to structure data and design efficient methods to process it.

DSA has become a bit of a “meme” in the tech space, because these interviews test skills that you will rarely use in the actual job.

However, it’s part of many interview processes, so it’s a necessary evil we need to practise.

If you did a degree in computer science, you would have likely studied DSA as a module, but many people looking to break into data science and machine learning come from other STEM backgrounds like physics, maths and engineering.

So naturally, these people start watching tutorials, reading textbooks, and are highly likely to use NeetCode as their primary learning resource.

I did the exact same.

I even wrote a series of articles about DSA on my blog at the time, whilst I was taking NeetCode’s “Data Structures & Algorithms for Beginners” course.

List: Data Structures & Algorithms | Curated by Egor Howell | Medium
Data Structures & Algorithms · 13 stories on Mediummedium.com

The problem is, this actually didn’t make me good at data structures and algorithms or at solving coding interviews.

I still struggled to solve basic problems like 2sum.

Don’t get me wrong, Neetcode is a great resource for learning concepts in DSA and wider areas like system design. But, its not the resource itself, rather the general approach to learning.

Sure, learning the theory is helpful, but you should learn it whilst practising at the same time to solidify your understanding.

It’s like wanting to play tennis and learning the theory of how to swing the racquet and learning the technique, but you never actually get to practise hitting the ball — which is fundamentally the whole game.

The same goes for LeetCode.

So, what I did is take the complete reverse approach.

I started doing the problems before even learning the topics. And then, after I have completed the problem or simply couldn’t solve it, learn the efficient solution and the accompanying theory with that topic.

This was my high-level process:

  • Spend 30–60 min per day on two problems for about 6 weeks straight first thing in the morning.
  • Give myself 20 minutes to solve each problem. If I couldn’t do it in that time frame, use the remaining 10 minutes to look through the solution.
  • When looking through the solution, I focussed on learning the pattern, not just the answer. This is so key, memorising solutions do not help you in the long run.
  • Close the solution, wait 5 minutes, and try to solve the problem again.
  • Rinse and repeat.

This approach transformed my understanding of DSA because it forced me to learn from doing, and to put myself through a so-called “mental sweat” as Andrej Karpathy calls it.

Passively watching courses and consuming books feels productive, but it’s actually procrastination — avoiding the actual work of solving problems and learning through failure.

Stop Practising All Topics

Now, I don’t want you to go ahead and solve any random problem on Leetcode, but rather focus on a select few topics that appear the most.

When it comes to data science and machine learning roles, the DSA knowledge doesn’t need to be as extensive as it is for software engineering positions, even if you are going for senior jobs.

In reality, only certain topics appear frequently in interviews, which are:

  • Arrays & Hashing — Use hash maps/sets for O(1) lookups to avoid rescanning data.
  • Two Pointers — Move two indices toward each other (usually in sorted data) to skip nested loops.
  • Sliding Window — Expand/shrink a contiguous range to track the best subarray/substring efficiently.
  • Linked List — Rewire node pointers carefully, often with fast/slow pointers or a dummy head.
  • Binary Search — Halve the search space when data (or the answer) is sorted/monotonic.
  • Stacks — LIFO structure for matching/undoing things or tracking “next greater/smaller” elements.
  • Trees — Traverse recursively (DFS) or level-by-level (BFS) to compute or search hierarchical data.
  • Heaps / Priority Queues — Get the min/max fast, ideal for top-k or “process most urgent next” problems.
  • Graphs — Traverse nodes/edges via DFS/BFS to explore paths, connectivity, or shortest routes.

Please focus only on these topics.

Topics like dynamic programming, tries, and bit manipulation are very tough to learn and don’t appear frequently in interviews.

That time spent learning these advanced topics is better focussed in other areas of the process like system design or behavioural interview prep.

To be honest, I have only ever practised 40 Leetcode problems and that allowed me to pass over 90% of my coding interviews, some of which were for senior machine learning engineer roles.

These 40 problems were intentionally chosen as they cover the key topics asked in interviews.

These were sampled from the popular NeetCode 150 and Blind 75 lists, but specifically targeted for data science and machine learning roles, since those lists are mainly aimed at software engineers.

I have created a nice table/database of these exact 40 problems that you can find linked below to help you with your preparation.

40 Must-Solve LeetCode Problems
These 40 problems got me $200k+ offers from companies like TransferWise, DoorDash, and at multiple startups.problems.egorhowell.com

Transparently, These 40 problems don’t cover every single possible question you could face in the interview, but they cover ~80–90% of the topics and types of problems you will get.

They are the highest-return-on-investment problems you can do in terms of time investment and passing interviews.

The goal of this problem set is to optimise your time to learn and practise the concepts that occur most frequently during the interview.

We are deliberately not being comprehensive; it’s all about strategy.

Stop Doing it Alone

Learning to solve coding and DSA problems is not that complicated; it all comes down to consistency and showing up every day.

If you are prepping a couple of days before, you are likely going to fail because you can’t learn DSA in such a short space of time.

It took me about 6 weeks to feel confident in coding interviews implementing the strategy I mentioned earlier and focusing on those 40 questions only.

However, no “hacky” approach works if you are not putting in the reps every day and staying consistent.

And this is where most people fail.

It’s like going to the gym — you know what you need to do and when to go, yet many people still don’t do it.

It’s not a knowledge problem, but a discipline problem.

This is why personal trainers exist: to keep you motivated and accountable to your goals.

You need the exact same thing for LeetCode/DSA.

When I was practising, I literally had my mum check in on me every week to ensure I was on track with my practice.

That accountability, and not wanting to let my mum down, is what drove me to do problems even when I didn’t want to. Accountability is a crazy mechanism for consistency.

So, I want you to do the exact same. Get anyone you know to reach out to you every day to keep you accountable.

I do this with certain clients in my coaching programme. I reach out to them every single day to ensure they are doing the prep they told me they would do.

This the simple tracker we use, so feel free to make a copy of it and use it for yourself.

Find the tracker here!

It’s unbelievably effective, and they all make tremendous progress toward getting their dream data/ML job.

If you are interested in working with me, feel free to apply below:

Apply here!

Connect With Me

Share this Article
Please enter CoinGecko Free Api Key to get this plugin works.