How to Learn Data Structures and Algorithms for Your Coding Interview

What’s up everyone. Sam here from and today I want to give you a framework for how you can approach your
data structures and algorithms for your coding interview so that you can go into
your interview and absolutely crush it. Alright so in this video, as I mentioned,
I want to give you a specific framework for preparing for your data structures
and algorithms for your interview. And this is so, so important because at
the end of the day, all of your interview ability comes down to how well you
understand the fundamentals. Particularly, let’s say you went to a boot camp or you
learn this stuff on your own and you don’t have that background, this is
incredibly important because by understanding the core fundamentals, it’s
gonna allow you to really problem-solve in your interview. No matter how many
strategies you practice, no matter how many strategies you learn, no matter how
many you know practice problems you go through, it all comes back to that core,
those core data structures and algorithms and that’s really where
you’re gonna have the most success when you’re interviewing. If you have those
fundamentals down cold, you can go into your interview and be confident.
You can go into your interview knowing that you know your stuff, and that
even if you see a problem that you haven’t seen before, even if you don’t
exactly understand what to do, you’re going to be able to figure it out
because you know all the fundamentals. And that’s why I’m so excited to share
with you this framework today. And so the way that this framework works is that we
are gonna break everything down into three steps. And before we get into the
framework, I want you to think about something for a second. What is actually
the difference between data structures and algorithms? We always talk
about these basically as one thing. We talk about them as a cohesive unit
where we say, I’m gonna study data structures and algorithms; I’m gonna
study DS and algos… We always combine these. But the fact of the matter is that
they’re not actually the same thing. A data structure is literally
how we structure the data, how we store in memory. Whereas an algorithm is
something that we’re doing to operate on that data. And so as we’re studying these,
I want you to start thinking about how we can break these out. And I want to
give you this framework of the three concentric circles
you can use as you’re preparing. And so when you’re preparing, you want to start
with the core data structure. This is in the center of our circle; this is in our
innermost circle. And you’re gonna start with just that core data structure. That
means, like, let’s say that we were talking about lists, you would understand
like what a list is, you would understand how that data is arranged. You would
understand what the classes look like. How everything is actually structured
and how that’s stored. This is the innermost section because, without
knowing that, we don’t know how to operate on that; we don’t know how to do
anything with it until we understand that data. And so a great thing to do at
this stage would be, if you’re practicing a specific data structure and algorithm,
implement the data structure. Like write a function that’s going to
actually take in some data and implement it. Write a function that’s going to
generate a tree from your data. Write a function that’s going to generate a
linked list and actually create that data structure. So this is the innermost
circle. And once we understand how the data is actually
structured, and once we understand how to implement that, now we move one step out. And we move to our core patterns. And also by the way, if you’re liking these
video editing skills because I’m getting really fancy with this, definitely hit
the ‘like’ button down below because that really helps with the video. So we move
out to this second circle, which is our core patterns. And so once we’ve
implemented our data structure itself, we’re gonna move one layer out into the
core patterns. And these are where we start to get interesting. The core patterns
are really those key algorithms that you need to know related to a given
data structure. And so a great place to figure out what those core algorithms
are is to look up the standard implementation of a specific data
structure. So like for example with Java, you might look up what is the list
interface, if you’re implementing a list. Because it’s gonna show you that
there are things like adding a node to a list, removing a node from a list,
reversing the list, getting the end element of the list… All of these
different things are sort of core to that data structure. Those are the
core algorithms that you want to be thinking about with that data structure
and that’s where you’re going to start when you are
implementing the data structure and when you’re learning this data structure.You
want to move out to what are the core algorithms because this is really what’s
gonna form the foundation for everything else. So let’s consider an
example again. If we had a linked list, we would have started by implementing the
linked list as our data structure. And now we’re gonna look at what are all of
those core patterns related to a linked list. We might want to be able to insert
or remove an item from a linked list. We might want to be able to reverse a
linked list or swap two nodes in a linked list or all of these sort of
basic things… We want to be able to get the length of a linked list or split a
linked list in half. The list goes on and on but these are all
basically like the fundamental building blocks of things that we do with a
linked list. And so what I want you to do when you get to this second level, once
you know how to implement the data structure, you should implement all of
these functions. Because the best way to learn, the best way to understand
how this works, is to actually go and implement it yourself. So the easiest way
to do this when you’re practicing a new data structure,
create your own class for that data structure, and start implementing
all these functions and learn how they’re implemented. With some of these
data structures, even basic things are not that easy to do. Like with
trees, removing a node from a tree might sound like a relatively easy
thing to do, it’s a basic concept, but it’s not as trivial in actuality because
we have to figure out what the heck are we gonna do with all the children.
And so the step two of learning the data structures and algorithms is to
implement these core data structures… or these core algorithms, sorry. And
then finally, we’re gonna move out to the outermost ring. And this is where we
start to get into the compound algorithms. And what that really just
means is that these are algorithms that are composed of two or more core
patterns. Two or more of these simple algorithms, two or more of these basic
pieces, that are combining together to make something more complicated. And so this is where all or most of the questions that you’re going to get asked
in your interview are actually gonna lie. They’re all going to be in this like
outer circle where really all we’re doing to solve the problems is
we’re just combining multiple different patterns. And so if we understand the
patterns and we understand how to combine them together, it’s basically
like a puzzle. At the end of the day it’s just a matter of combining them
in some sort of creative way so that we can get to the solution that we want. And
so like a perfect example of this is, let’s say that I asked you to write a
function that would print a linked list out in reverse order. It’s
really easy to do this because all we have to do is combine a couple core
patterns. So we could combine the core pattern of reversing a linked list with
iterating over a linked list. And then all we have to do is we reverse the
linked list then we iterate over it and print it. And then we might want to
reverse it back, depending on whether we care about the data. So that would
be like a really simple example of how we could do this, where we’re just gonna
take those core patterns and we’re gonna do something with them. And the same is
true with so many different problems. Like whenever you’re approaching a
problem, especially whenever you’re approaching a new problem that you
haven’t seen before, I would encourage you to think about, how do I take this
problem and break it into smaller chunks? How do I break it into smaller
core patterns? And by doing that, you’re gonna see that so many different
problems can be solved just by combining a series of core patterns. And so that’s
the way that this works. I really want you to start applying this framework
because it’s so valuable when you’re thinking about how you approach these
problems, to think about it in a structured way. And when you’re
thinking about data structures and algorithms in general, it’s really
important that you have a structured approach. And finally, I want to give you
one more tip that you can use to figure out what you actually need to focus on.
Because a lot of times there are so many different data structures and so
many different algorithms that the question always becomes, like, ‘Well do I
need to focus on this, do I need to focus on that? Do I need to focus on red-black
trees? Do I need to focus on priority queues?’ And the answer is you want to
start at the core and expand out. It’s the same as this framework.
You want to start with the most important algorithms and expand out from
there. So if you have Cracking the Coding Interview or you have Elements of
Programming Interviews, you can look at the table of contents and see like those
the core data structures of algorithms that you really need to understand. If
you don’t have the books, you can go on Amazon and just look at the
table of contents on there, but that will give you that core set of data structures
and algorithms that you need to know. So you can take those that apply this
framework to that core set of data structures and algorithms. And then once
you know those, you can start getting more creative. You can start expanding
out from that core set to start understanding others. You can start
implementing rebalancing trees. You can start implementing priority queues and
you can play around with different things.
But if you don’t understand those core data structures and those core
algorithms first, then you’re going to go into your interview and you’re gonna
know all about A* search and you’re gonna know all about red-black trees, but
you’re not going to be able to implement a simple linked list problem. And
so the key with any interviews is focusing on the key parts first. Focusing
on the most reusable parts and expanding from there. So that’s all I got for you
today. I hope you have a chance to apply this strategy. Let me know in the
comments below what you think of this and how you’re gonna apply it. Let me
know what data structure you’re gonna apply this to first. And if you enjoyed
this video, definitely subscribe and give us a ‘like’ below and we also have our
free 50 questions guide that you can download as well. And so I look forward
to seeing you all in the next video.


  1. Helpful Sam. A list of core patterns would have been great. Also, few more examples on how to combine them to solve a specific problem

  2. keep making these video man…Thank you so much. I have an interview coming up really soon. your videos have been of immense help to my practice.

  3. Love this video, and I would like to suggest Mosh Hamedani's 3-part course on Datastructures and Algorithms, which follows the outline in this video… 1. Implement the data structure from scratch, 2. Build core patterns and 3. Solve common coding problems with the data structure.
    (disclaimer: I'm in no way making money off my endorsement, it's just that the course is sooo good!)

  4. In my opinion, the fastest way is to do Leetcode problems and look at the solutions. When you see a data structure or an algorithm that you are not familiar in the solution, learn it by watching YouTube videos. You will save a lot of time by doing this since you won't waste time on learning stuff that's not in coding interview.

  5. Main problem for me is how to approach problem with proper algorithm. We have learn many algorithms but when we read any problem then how to decide which algorithm is perfect or which strategy like greedy or dynamic etc. Without that understanding you can't apply correct algorithm or think most suitable strategy. I gone through your books of 50 questions but still didn't understand how you deciding the solution or algorithm. Example median of two array, you solved it and I understood it but still not able to relate it with any strategy of algorithm other than recursion.

  6. thanks very much sir
    I do have a question on javaScript.
    I know all the foundation of javaScript and I was wondering how can I start learning datastructure and algorithms.
    I am really confused
    please, your help would be really appreciate.

Leave a Reply

Your email address will not be published. Required fields are marked *