have you ever been flustered in a coding
interview maybe was because you weren't
able to find the right data structures
or algorithms to use in a problem
quickly in this video I'm going to show
you how to find the optimal answer in a
coding interview quickly just as an
example let's consider this maximum sub
array problem now what's a sub array a
sub array is basically an array within
an array so an example of a sub array
would be 2 1 or it could be just one
element negative 3 or it could be the
whole array that's also sub array but if
we had instead negative 3 and let's say
1 that's not a sub array because these
are not contiguous elements so a sub
array is a set of contiguous elements
within the given array now the problem
here is finding the sub array with the
maximum sum here's what I mean if we
look at this sub array 2 1 the sum is 2
plus 1 equals 3 and if we look at this
sub array with just negative 3 the sum
is negative 3 and we are trying to find
the one with the maximum sum and in this
example it's actually 2 1 with the sum 3
and you can check it yourself too and
let's say you're given this problem in
your interview and you don't know how to
solve it and you can't figure out the
solution right away what should you do
about it
there are 4 tips I want to give you here
for finding the right solution very
quickly
tip number 4 is just say can I think for
a second whenever you start thinking you
know most candidates become completely
silent when they start thinking and it
could be really awkward for the
interviewer because they don't know what
you're doing so you should really
clarify whenever you start thinking tip
number three's think out loud once you
say that phrase can I think for a second
you should start thinking out loud
instead of silently I know for some
people it's easier to think silently but
you don't have to overdo this you just
need to let the interviewer know where
you are in your thought process and the
way I would do it might be something
like this I would say okay I noticed
that there are positive numbers
here in this example and also negative
numbers and if we only had positive
numbers let's say one to one then the
problem would be much easier because
then the maximum sub-array would just be
the whole array so what makes it hard is
the fact that we have negative numbers
so maybe we can do something separate to
the negative numbers and the positive
numbers in the array and when you say
something like that the interviewer is
going to say either okay you're going in
the right direction or in the wrong
direction and that's going to be really
helpful for figuring out what the right
solution is so you shouldn't think of
the interview as a monologue or a solo
problem-solving session you should think
of it as more of a collaborative thing
as a conversation so you shouldn't have
to solve everything by yourself when the
average candidate is given a problem
they just start writing code but you
shouldn't do that you should first think
through examples and think of a few more
examples then add that just given one so
in this problem I might say okay this is
a of course a given example but I can
think of a few more examples what about
all positive numbers and what about
maybe all negative numbers and when you
start thinking through examples you'll
be able to think in a much more concrete
way than trying to think of everything
in an abstract way let's say you start
thinking through examples and you come
up with a solution then you should ask
does this seem like a good strategy
unless you're 100% sure that your
solution is optimal and the way I would
do it in this example might be something
like this I would say okay my solution
would be compare all the sub all the
possible sub arrays so the ones starting
at the first index and then the ones
starting at the second index and I will
compute the sum for each sub array and I
will just pick the one with the maximum
sum
so it's a brute-force strategy and then
I would ask to the interviewer does this
seem like a good strategy when you say
that you're essentially giving some
space to the interviewer so they can
give you feedback as to if you're going
in the wrong direction or if your
solution is really optimal and this way
you don't have to waste time writing
code because you didn't write code in
the first place you don't have to waste
time writing code for solution that
doesn't work oh that's not optimal so
just to recap say can I think for a
second when you start thinking think out
loud instead of silently you don't have
to overdo this you just need to let the
interviewer know where you are thinking
from time to time and don't start
writing code right away use examples
first and finally when you come up with
a solution
just ask does it seem like a good
strategy and these are more for tips for
finding the optimal solution in a coding
interview quickly I hope you liked the
video if you want to watch more videos
like this you can click right here to
subscribe to my channel and see you soon