hi I'm the tech lead and today I'll be
the tech lead I wanted to talk today
about some of the top algorithm snow for
the coating interview I've conducted
over a hundred interviews for large tech
companies and I've also gone through
interviews myself too so I thought that
was share some of my top tips as you're
preparing for your interviews today we
are drinking coffee I'm taking it black
because it is a serious topic and I'm a
serious man oh that is so professional
the aroma is just so sophisticated now
there are a lot of different algorithms
to study and to know but I thought I
would key you in on some to focus on
especially one of the top algorithms to
know is tree traversal tree traversal is
used heavily in the industry and I would
be highly surprised if you went through
an interview without getting asked at
least one tree traversal question if you
think about it there's not that many
tricky algorithms there's a few you got
to know and that you should know very
well and one of them is tree traversal
so as far as that goes this involves
knowing how to traverse a tree in a
number of ways there's preorder
traversal inorder traversal post order
traversal breadth-first search and
depth-first search one common problem is
given the view hierarchy where there's a
view sub views and sub sub views
traverse every view and print the view
this can be modeled as a tree problem
and you should not have to do it
recursively and iteratively there may
also be scenarios where you need to do
breadth-first search to find the nearest
note that matches some criteria the
binary search algorithm also
occasionally shows up in interviews
where you need to traverse some tree
structure looking for some node and that
can be done in logarithmic time you
should also know how to use data
structures to represent a tree in my
data structures course they taught tree
structures as having a node with a left
node and a right node but I think that
was probably kind of naive because that
limits the fan-out
to two and if you want more larger
fanouts then what really makes sense is
just having an array so really all you
need to represent a tree is a node with
an array of children nodes inside now we
know that recursion is a common way to
traverse these tree structures but
surprisingly a lot of people think they
know recursion but I don't think they
know it well and they
elegantly and what commonly happens is
that when you start writing a recursive
function you start needing to pass
parameters to represent state and then
your recursive function gets bigger and
bigger and you start needing to pass a
bunch of variables into it so one thing
to think about is commonly recursive
programs need helper functions where you
call into the recursive program and in
that recursive program call straight
into the helper function but passes in a
set of initialization variables that can
help keep your code and the API clean
you also want to think about what your
base case is because if you can clarify
what that base case is at what point the
recursive function will end that usually
helps you write a cleaner function
recursion is another favorite interview
question and that would be surprised if
it weren't asked now the thing to know
is commonly attack recursion is not
actually used all that often because it
is limited to stack space because of
that recursion has limits and is not
that optimal and usually what
professional developers will do is
convert that into an iterative function
so this is where you can start looking
into gaining extra points it's good to
know that every recursive algorithm can
be converted to an iterative algorithm
using stacks or queues and I encourage
you to try practicing out some of this
stuff like try taking one of your
favorite algorithms like say Fibonacci
or tree traversal and try implementing
that iteratively and see what you would
need for that
you might find that in some scenarios
some recursive algorithms are actually
pretty difficult to do iteratively and
others are not and that really depends
on how much estate you're passing from
one recursive iteration to the next one
so that's just a pro tip is sometimes
all the interviewers looking for is the
recursive algorithm because the
iterative algorithm may require too much
overhead to complete but you want to
keep that in mind
speaking of stacks and queues these are
often used very commonly in interview
questions one common question is given a
string of parentheses check if they're
balanced and that can be done with a
stack you just push them and pop them as
you go most languages have support for
stacks and queues like array pop push
shift unshift vectors so you just wanted
to want to make sure you're familiar
with those language syntax and features
the other one to note here is object
oriented programming which also comes up
quite often in
and you're going to want to bring out
the object-oriented programming where
ever you can just to show that you have
some sense of Co structures and
organizing code so for whichever
language you're choosing make sure you
know how to create a class in that
language set the methods private
variables public variables and as you
approach a problem start thinking about
what potential data structures you may
need to solve the problem and if it
makes sense to create a class for that
sometimes using classes can even
simplify your work for example instead
of using a 2d array to represent a grid
you can set up a grid class and then you
can just use that grid class and call
methods on it and pretend that these
methods exist and fill them in later if
you have time that might actually help
you save some time because you can
assume that this class will help take
care of things like edge checks
sanitation validation maybe provide
certain helper methods that you might
need and it may help you progress
further through a problem that you
normally will be able to speaking of
data structures hashmaps is another one
that you have to know many algorithms
can be solved using hash maps it's a
simple trick and and give you a little
secret here if you happen to get stuck
on the interview question start thinking
about hashmaps
stacks queues these basic data
structures are probably going to be
involved in any optimal solution
hashmaps I used very commonly in any
interview question so you should
definitely understand how to use them
you should understand their time-space
analysis and you should understand how
to use them like given some language of
your choice how do you create a hash map
how do you populate it what's the syntax
for that and you should also be able to
know how to create hash maps of other
hashmaps hashmaps keyed on strings
integers or even objects where you may
need to compute a hashing function and
be able to answer to interviewer if they
ask you what the hash stream function
may be one common interview question
with hash maps is to sum were given an
array of integers find two integers that
sum up to some number and using hash
maps you can go through the array in one
pass and figure out which two numbers
sum up to some number and that's another
thing to keep in mind is how many passes
you might need like oftentimes an
algorithm might require one pass to
process data in some way and then the
second pass to actually compute the
solution so keep that in mind sometimes
you may need to do two passes or even
three passes that's still going to count
as a linear time algorithm because
you're still doing a constant number of
linear time passes when I used to do
interviews I would answer them in PHP
because I thought that that was a very
quick language and I still might use
that sometimes but I've decided to also
add C or C++ to my language mix because
sometimes I get questions that can only
be answered using C or C++ these are
questions like reversal linked list
since PHP doesn't really use pointers it
just doesn't work very well for the
question so be prepared to have C or C++
at your language disposal in case you
get asked to do something like reverse a
linked list you're going to want to be
able to pass out those pointers for a
question like that or you can just use
pseudocode but
pointers are generally one aspect of
computer programming that trips a lot of
people up interviewers might just ask
you that just to see if they can catch
you that way sorting is another area
that you should study up on especially
the runtime analysis of it in practice
people probably won't actually ask you
to implement any of these in detail
especially the complicated ones like say
quicksort
I think some of these are good to know
like say bubble sort or merge sort but
the rest if you have extra time and
bandwidth then go ahead and study up on
those though if you like and then the
final tip is to know how to work with
strings in your language of choice
know how to construct them know how to
iterate through them character by
character they know how to solve some
common algorithms like determine if the
string is a palindrome or an anagram now
one area we haven't talked about too
much as dynamic programming and I think
that dynamic programming scares a lot of
people because often is an aha moment
where you either get the algorithm or
you don't and if you got it then you can
solve it very quickly and if you didn't
it would take you a really long time to
figure that out so my opinion you should
know the basics of dynamic programming
but don't waste too much time studying
it because I would be surprised if an
interviewer were to actually ask you a
dynamic programming question like I
think those are really pretty tricky and
people are generally discouraged from
asking questions are too tricky or too
involved but many times dynamic
programming
all it is is memorization where you're
caching the values as you're going
through the algorithm and just by
caching the values you're solving
subproblems as you go through and then
you can reuse the results of those
subproblems to compute the final answer
so as far as that goes if you keep in
mind caching and solving smaller
problems and then caching those and
reusing that value that's pretty much
dynamic programming for you so those are
my overall tips but I want to remind you
once more that solving the problem
itself is not the goal it's really the
process and my process I mean is going
to be in your analysis of the problem
how well can you analyze it how well can
you look at the design alternatives
trade-offs pros and cons in terms of
time and memory big-oh time space
analysis often times there's many ways
to solve a problem it's going to be a
trade-off between time and memory and if
you can just bring that out and mention
like well if you want to optimize for
time we're going to want to use this
data structure and solve it this way if
you want to optimize for a memory we're
going to do it this other way for
example you may be able to find an
optimal time algorithm using some hash
map but then you're using a lot of space
but would've been great if you could
point out well if you want to be space
efficient but not necessarily time
efficient then you can use some other
algorithm that may be quadratic time but
doesn't use the hash map that would be
great to show
similarly if there's a recursive
algorithm point out the pros and cons of
using that versus an iterative algorithm
now I have one more tip for you and it
is in this box
unless this brilliant org what this is
amazing brilliant ax org is an
educational website that can teach you
all sorts of things including computer
science fundamentals and algorithms and
I'm a big fan of continued learning I
even used the site myself to learn more
about machine learning
algorithms their courses are done in
there really beautiful and interactive
way they make learning a lot of fun and
there's a broad range of other fun
topics on here too including logic math
science physics astronomy a lot of their
content is free and very high quality so
you can browse around their website for
hours learning about topics that you may
be interested in so to support tech lead
and to learn more about brilliant go to
brilliant Dow org slash tech lead and
sign up for free and also the first 200
people that go to that link will get 20%
off the annual premium subscription I'll
do it for me good luck and see you next
time bye