hey everybody,
welcome to your expert in this video.
some,
this question basically gives you an array of distinct integer values,
meaning that no number in the array is repeated,
and it also gives you a separate integer value that represents a target sum.
that sums up to the target sum.
so in this example,
you know,
five,
negative,
four,
eight,
eleven,
one,
negative,
one,
six.
that sum up to ten.
and there is,
we can have the numbers eleven and negative,
one with you.
indeed,
sum up to ten eleven plus negative one is equal to ten.
so i really like this question,
meaning on algo expert di o.
you will actually find two other questions in the array section,
or category one of them is called three number.
some,
the other one is called four number some,
except they ask you to find a triplet that sums up to a target sum or a quadruplet.
you know,
four numbers.
but this question is the easiest of the three.
it only involves two numbers.
that being said,
because it will teach you a lot,
so how do we do this?
how do we go about implementing an algorithm that you know traverse this array and somehow find the solution?
the first thought that you might have is to kind of use two,
four and traverse the array twice to find the sun.
and that would work,
right.
you could traverse the array once go through each of the numbers and individually,
and then at each number,
traverse through the rest of the array and kind of kind of find the sun and other words,
you know,
you could start up three and reverse all the other numbers here and see if adding any of these numbers to three yields ten,
then you move on to five and you traverse all the other numbers and see if adding any of them to five.
yes,
the ten and so on and so forth,
right?
but the thing is,
right?
oh,
and squared time,
four.
so perhaps a better way of solving this here is to use a hash table,
but it might make our algorithm faster.
so what do i mean by using ash table?
so basically we can store,
we can traverse our right here and store every number that we see in a hash table,
which is going to allow us to them access these numbers in constant time,
through that hash table.
so alright and green here.
what do we have a hash cable at the top,
which you can represent as you know,
a python dictionary or javascript object,
whatever you want in the in your language of choice.
so now now that we have this hash table of numbers,
um,
and at each of the numbers that we traverse right now,
each of the numbers that we stop at,
which is ten,
is stored in this hash table.
so in other words,
some is equal to ten.
and whenever works,
reversing the array,
which is equal to x x,
is whatever number were at.
as we traverse the array,
and so we want to find why the number y such that x,
plus y is equal to ten,
or in other words,
we can isolate why to be,
why is equal to ten minus x.
so basically,
as we traverse the array,
we have the value ten,
which is our target sum.
we have the value x,
which is whatever number or currently at,
and all we need to do is apply this formula,
solve this equation to find why.
and then we say,
is,
why is in our hash table and we can do that in constant time accessing,
you know why in the hash table,
if it is a little hash table then we just return x and why?
otherwise,
we keep traversing the array,
and we just make sure to store x in the half table.
we started the number three,
and we,
we say,
okay,
why is going to be equal to,
why is going to be equal to ten minus three other words,
why is going to be equal to seven,
is seven in our hash table?
no,
but well we can do now is we can store three in our hash table.
you can store three to be screw or whatever value you want to store it as true here just kind of indicates that,
yes,
three is present in our array.
so now we move on to five and we say,
okay,
if we have the number five,
no,
so we skip this.
we do.
we have in found our two number,
then we move on to the number minus four,
and we solve for why?
so we say,
is ten minus negative four,
equal or ten minus negative four is going to be equal to fourteen is fourteen in our hash table.
no,
so we just store negative four to be through in our hash table,
then we get to this eight we saw for why.
so ten minus eight is going to be equal to two is two in our house.
cable.
no,
five and negative four,
so we can skip this,
and we can just store eight as true.
and you kind of get the idea now,
right?
so the rest of this should go pretty fast.
we go to eleven,
so for y ten,
minus eleven is going to be equal to negative one.
one in our hash table.
no,
at least not yet.
so we just store eleven.
then we move on to this one.
nine is not in our hash table,
so we go store one,
and now we get to the number that we care about.
we get to negative one so we can calculate ten minus ten,
and now if we check for the number eleven in our hash table or will notice that we have it here,
right?
so because eleven is in our hash cable,
um,
return eleven and negative one.
we found our answer.
so how are we doing in terms of space,
time,
complexity,
analysis?
well,
the time complexity here is just going to be o of n time where and represents the length of our input array.
why is it just,
oh,
over time,
right solving for why,
as is the constant time operation,
which was doing a calculation,
you know,
we have the target sum.
we have the number x here,
which is whatever the current number or at,
which is going to run in constant time.
so total time complexities,
oh then,
now the space complexity is also going to be oven,
because we are adding values to a hash table.
and so here we kind of saw that we went all the way to this negative one,
this kind of the before last number in array.
so we did store a bunch of values,
which kind of the neared and values in our hash cable.
but so the space complexity is going to be over than if we had done this using just two four loops without a hash table,
we would have gotten constant space,
but we would have gotten old and squared time because of the double four loops in the sort of double aeration through the array.
anyway,
so before we dive into the code,
walk through,
i have to pologies because i just realized that i totally forgot while i was filming the video,
to mention a third way.
so we can solve this problem,
that is definitely worth mentioning and worth covering.
basically,
we had this array of numbers,
right?
and when we,
in other words,
sorted.
but we can solve this problem more optimally without using a hash table by first sorting the array more optimally than the solution.
with two four looks.
so if we sort the array here,
we know that,
you know,
good sorting.
algorithms,
like quick,
sort,
emerged for,
or heap,
sort will take o n log n time so we can have a time,
complexity of o n log n.
and then we naturally find the answer,
which is going to be a eleven and negative one here in o n time.
and because we can find it in no event time,
we have a total space or a total time complexity of o.
then log n from the sorting of the beginning,
so of one space,
how this works.
basically,
what we can do is,
and by the way,
the same logic is applied.
another question on the website,
the one called three number,
some.
definitely go check that one out as well.
so what we can do is we can put a left pointer initialize it to be under under the first number in the array.
and we can put a right pointer under the very last number in the array and the skies eleven.
and so what we can do is we can sum up the two numbers that l and r point two,
so we have negative four,
and once we have the sum,
we can compare the sum to our number.
so this sum is going to be um seven and so we can compare seven to ten.
now is seven equal to ten.
no,
so this is not about some right,
negative four and eleven or not a valid some,
but what we can say now is we know that seven is less than ten,
right,
and all of our numbers here are in sorted order.
then what would happen if we were to move the right pointer?
well,
if we were to move the right pointer to the left right here to this eight,
we know that this eight is less than eleven because the array is sorted,
and because it is less than eleven,
then our new,
some here is going to be even even smaller than seven,
which is already smaller than ten.
so instead of moving the right pointer to the left,
we know that we should move the left pointer to the right because we want to try to have.
greater sum,
and so if we,
if we move the left pointer to the right,
then we get this negative one.
and so we can update our some to be negative.
one plus eleven equals two ten.
and now we have our actual answer,
because ten is equal to ten.
um,
to make this more interesting.
had been um sixteen okay,
so eleven plus five,
or rather,
no,
not eleven plus five.
okay,
so if we were looking for the number thirteen and the answer was eight,
plus five,
eight,
plus five,
then what we,
what we could do is um,
we would have the,
we would have here the sum ten and ten would be smaller than thirteen,
because we know that moving the right corner to the left would give us a smaller sum,
which would be smaller than ten,
which would be smaller than thirteen for sure.
so we move the left pointer.
plus eleven is.
going to be equal to twelve,
so we compare twelve to our target,
which is thirteen twelve,
less than thirteen.
so once again,
we have a sum that is too small,
so we can move the left pointer to the right.
now we have three,
so we sum three and eleven,
and we can erase this.
three plus eleven is going to be equal to fourteen,
and now fourteen is greater than thirty for some,
n is bigger right.
there are some is too big.
so what can we do?
we know that if we move the left pointer to the right,
so what we do is we move this time around the right pointer little the left.
so we can update this eleven here to be eight and three plus eight is going to be equal to eleven.
equal to thirteen.
no,
so again,
which would be a bigger number,
and we eliminated all of them.
so we want to move the left pointer.
so we move the last point to the right.
now.
so five plus eight and um five per cent is going to give us thirteen.
the number that we want.
and that is our answer.
and we just have the left pointer in the right pointer,
that is constant space.
we all use an extra hash table or anything.
and in terms of time,
we actually run in oath and win,
and the actual lake algorithm that we just described here with the left and right pointers runs an oath and time,
because at the most,
you know,
and eventually they get equal to each other.
and in total,
you know,
once or twice.
and so that.
convert is to owe them time.
therefore we can write the time to be oh,
of an and.
and the space can be written as o of one,
which is constant space.
so this is a really cool way to solve this algorithm.
once again,
i apologize for having forgotten about it.
some questions,
so definitely check it out if you want to see how it works.
and in the context of that question,
which is a bit more complicated.
walk through of all these solutions.
all right.
some function to find it takes an an array of distinct integers and an integer value,
representing the target sum.
which is going to run in of n squared time,
where n represents the length of the array.
for that solution,
all we have to do is literally implement two,
four weeks,
it will say four i and rain um when of array minus one we want to go all the way to the before last value in the array.
and then we can say we can say current num,
or rather,
first numb kind of declare our first variable is going to be equal to array of i,
and then we can say four j in range.
i plus one one of array.
here we can,
you know,
we can say,
second,
num is going to be equal to array of the j.
right?
and then we say,
yes,
first,
numb plus second equals target some,
and just return an array of first and second,
none.
then at the end we can here return an empty array.
statements in the double four loop.
so that is the first way of falling this problem,
here is just for readability purposes.
and then at the end were returning either an empty array or an array of two values.
all right now,
the way that we really covered in the conceptual overview with uses,
the hash cable.
this is going to be the different,
so two number,
some array target,
some has the same two parameters.
the dictionary here in python,
or a javascript object.
and work is going to call it a numbs ford for numbers.
four,
numb in array.
minus num is in our numbers.
have cable.
now what is target,
some minus snub?
right,
in the conceptual overview that we called why this is basically are equation.
you know,
why equals target some minus x?
that was the equation that we cover in the conceptual overview.
so if target,
some minus numb,
which is the y value is present in our numbers.
hash table,
well,
then just return target,
some minus num,
comma.
num,
okay.
otherwise,
a numbers of numb is going to be equal to true.
otherwise we just store our current number in the hash cable and we can restore it as true or whatever you want to put here.
right,
i think through makes the most sense here.
and then at the end,
if we never hit this return statement,
and so here,
by the way,
it might be for readability purposes,
in it might be better to declare you know potential potential match equals target some minus numb.
and then here we can and have,
replace target,
some minus,
numb with potential match.
this is going to run in o of an end time,
not and squared time.
but it will also run in oven space,
so i hope this video was helpful.
i hope it taught you um how to solve this algorithm.
and really,
i hope it show you how you can use hash cable to your advantage.
oftentimes hash table will make your algorithm use up a bit more space,
but run faster and more efficiently.
especially in more complicated algorithms that might use our space no matter what,
in which case,
but will actually help you from a time point of view.
all right,
for this video,
alright.
so the video is not over yet.
we still have this third solution that i mentioned earlier in the conceptual overview to implement in code.
right?
but at the very beginning,
our built in python,
sorting function um and assume,
or hope,
rather,
that it uses an optimal sorting algorithm like,
quick,
sort,
merge,
sort and runs in an oven log n time where n is the length of the array.
and so then we can initialize our left pointer to be equal to zero.
the first value in the array and are right pointer to be equal to the final value in the array,
or the final index in the array,
one over a minus one.
so then we can have a while loop,
and we can say wild left is less than right for,
right?
or while there,
you know,
one of them is not while the left one is not pass the right one.
um the current sum is going to be equal to array of left plus array of right,
parentheses,
here is the current sum is equal to the target sum.
then we could,
we can just return um left and or rather array of left and array of right,
right,
the two numbers that we have,
and then we can say l s.
and here let me make a bit of space,
l,
with a current sum,
is less than the target sun.
if our print son is less than the target sum,
then we want to increase the left pointer so we can say left,
plus equal to one.
and then if the current sum is greater than target,
some right,
plus equal or right side,
a minus equal to one,
because then we want to move the right pointer to the left,
my one position,
otherwise we can just return the and theory if we get out of this while loop,
without having hit this,
twenty eight and without having returned you know,
two numbers,
the target sum,
and we were turned the empty array.
so this algorithm is going to run in o of n log n time,
run in constant space so you can kind of see that um the space complexity here is as good as the first algorithm,
with the double four loops better than the one with the hash cable and the time complexity is better.
definitely better than the one with a double four weeks,
but a bit worse than the one with the hash table.
so here,
if you were in an interview and you came up with all three of these solutions,
talk with your interviewer about the trade offs,
you know,
you value space more than a time in which casey use this last solution.
otherwise you use probably the solution with the hash cable if you valued time the most.
so i hope this video was informative for the second time around,
hey everybody,
welcome to your expert in this video.
some,
this question basically gives you an array of distinct integer values,
meaning that no number in the array is repeated,
and it also gives you a separate integer value that represents a target sum.
that sums up to the target sum.
so in this example,
you know,
five,
negative,
four,
eight,
eleven,
one,
negative,
one,
six.
that sum up to ten.
and there is,
we can have the numbers eleven and negative,
one with you.
indeed,
sum up to ten eleven plus negative one is equal to ten.
so i really like this question,
meaning on algo expert di o.
you will actually find two other questions in the array section,
or category one of them is called three number.
some,
the other one is called four number some,
except they ask you to find a triplet that sums up to a target sum or a quadruplet.
you know,
four numbers.
but this question is the easiest of the three.
it only involves two numbers.
that being said,
because it will teach you a lot,
so how do we do this?
how do we go about implementing an algorithm that you know traverse this array and somehow find the solution?
the first thought that you might have is to kind of use two,
four and traverse the array twice to find the sun.
and that would work,
right.
you could traverse the array once go through each of the numbers and individually,
and then at each number,
traverse through the rest of the array and kind of kind of find the sun and other words,
you know,
you could start up three and reverse all the other numbers here and see if adding any of these numbers to three yields ten,
then you move on to five and you traverse all the other numbers and see if adding any of them to five.
yes,
the ten and so on and so forth,
right?
but the thing is,
right?
oh,
and squared time,
four.
so perhaps a better way of solving this here is to use a hash table,
but it might make our algorithm faster.
so what do i mean by using ash table?
so basically we can store,
we can traverse our right here and store every number that we see in a hash table,
which is going to allow us to them access these numbers in constant time,
through that hash table.
so alright and green here.
what do we have a hash cable at the top,
which you can represent as you know,
a python dictionary or javascript object,
whatever you want in the in your language of choice.
so now now that we have this hash table of numbers,
um,
and at each of the numbers that we traverse right now,
each of the numbers that we stop at,
which is ten,
is stored in this hash table.
so in other words,
some is equal to ten.
and whenever works,
reversing the array,
which is equal to x x,
is whatever number were at.
as we traverse the array,
and so we want to find why the number y such that x,
plus y is equal to ten,
or in other words,
we can isolate why to be,
why is equal to ten minus x.
so basically,
as we traverse the array,
we have the value ten,
which is our target sum.
we have the value x,
which is whatever number or currently at,
and all we need to do is apply this formula,
solve this equation to find why.
and then we say,
is,
why is in our hash table and we can do that in constant time accessing,
you know why in the hash table,
if it is a little hash table then we just return x and why?
otherwise,
we keep traversing the array,
and we just make sure to store x in the half table.
we started the number three,
and we,
we say,
okay,
why is going to be equal to,
why is going to be equal to ten minus three other words,
why is going to be equal to seven,
is seven in our hash table?
no,
but well we can do now is we can store three in our hash table.
you can store three to be screw or whatever value you want to store it as true here just kind of indicates that,
yes,
three is present in our array.
so now we move on to five and we say,
okay,
if we have the number five,
no,
so we skip this.
we do.
we have in found our two number,
then we move on to the number minus four,
and we solve for why?
so we say,
is ten minus negative four,
equal or ten minus negative four is going to be equal to fourteen is fourteen in our hash table.
no,
so we just store negative four to be through in our hash table,
then we get to this eight we saw for why.
so ten minus eight is going to be equal to two is two in our house.
cable.
no,
five and negative four,
so we can skip this,
and we can just store eight as true.
and you kind of get the idea now,
right?
so the rest of this should go pretty fast.
we go to eleven,
so for y ten,
minus eleven is going to be equal to negative one.
one in our hash table.
no,
at least not yet.
so we just store eleven.
then we move on to this one.
nine is not in our hash table,
so we go store one,
and now we get to the number that we care about.
we get to negative one so we can calculate ten minus ten,
and now if we check for the number eleven in our hash table or will notice that we have it here,
right?
so because eleven is in our hash cable,
um,
return eleven and negative one.
we found our answer.
so how are we doing in terms of space,
time,
complexity,
analysis?
well,
the time complexity here is just going to be o of n time where and represents the length of our input array.
why is it just,
oh,
over time,
right solving for why,
as is the constant time operation,
which was doing a calculation,
you know,
we have the target sum.
we have the number x here,
which is whatever the current number or at,
which is going to run in constant time.
so total time complexities,
oh then,
now the space complexity is also going to be oven,
because we are adding values to a hash table.
and so here we kind of saw that we went all the way to this negative one,
this kind of the before last number in array.
so we did store a bunch of values,
which kind of the neared and values in our hash cable.
but so the space complexity is going to be over than if we had done this using just two four loops without a hash table,
we would have gotten constant space,
but we would have gotten old and squared time because of the double four loops in the sort of double aeration through the array.
anyway,
so before we dive into the code,
walk through,
i have to pologies because i just realized that i totally forgot while i was filming the video,
to mention a third way.
so we can solve this problem,
that is definitely worth mentioning and worth covering.
basically,
we had this array of numbers,
right?
and when we,
in other words,
sorted.
but we can solve this problem more optimally without using a hash table by first sorting the array more optimally than the solution.
with two four looks.
so if we sort the array here,
we know that,
you know,
good sorting.
algorithms,
like quick,
sort,
emerged for,
or heap,
sort will take o n log n time so we can have a time,
complexity of o n log n.
and then we naturally find the answer,
which is going to be a eleven and negative one here in o n time.
and because we can find it in no event time,
we have a total space or a total time complexity of o.
then log n from the sorting of the beginning,
so of one space,
how this works.
basically,
what we can do is,
and by the way,
the same logic is applied.
another question on the website,
the one called three number,
some.
definitely go check that one out as well.
so what we can do is we can put a left pointer initialize it to be under under the first number in the array.
and we can put a right pointer under the very last number in the array and the skies eleven.
and so what we can do is we can sum up the two numbers that l and r point two,
so we have negative four,
and once we have the sum,
we can compare the sum to our number.
so this sum is going to be um seven and so we can compare seven to ten.
now is seven equal to ten.
no,
so this is not about some right,
negative four and eleven or not a valid some,
but what we can say now is we know that seven is less than ten,
right,
and all of our numbers here are in sorted order.
then what would happen if we were to move the right pointer?
well,
if we were to move the right pointer to the left right here to this eight,
we know that this eight is less than eleven because the array is sorted,
and because it is less than eleven,
then our new,
some here is going to be even even smaller than seven,
which is already smaller than ten.
so instead of moving the right pointer to the left,
we know that we should move the left pointer to the right because we want to try to have.
greater sum,
and so if we,
if we move the left pointer to the right,
then we get this negative one.
and so we can update our some to be negative.
one plus eleven equals two ten.
and now we have our actual answer,
because ten is equal to ten.
um,
to make this more interesting.
had been um sixteen okay,
so eleven plus five,
or rather,
no,
not eleven plus five.
okay,
so if we were looking for the number thirteen and the answer was eight,
plus five,
eight,
plus five,
then what we,
what we could do is um,
we would have the,
we would have here the sum ten and ten would be smaller than thirteen,
because we know that moving the right corner to the left would give us a smaller sum,
which would be smaller than ten,
which would be smaller than thirteen for sure.
so we move the left pointer.
plus eleven is.
going to be equal to twelve,
so we compare twelve to our target,
which is thirteen twelve,
less than thirteen.
so once again,
we have a sum that is too small,
so we can move the left pointer to the right.
now we have three,
so we sum three and eleven,
and we can erase this.
three plus eleven is going to be equal to fourteen,
and now fourteen is greater than thirty for some,
n is bigger right.
there are some is too big.
so what can we do?
we know that if we move the left pointer to the right,
so what we do is we move this time around the right pointer little the left.
so we can update this eleven here to be eight and three plus eight is going to be equal to eleven.
equal to thirteen.
no,
so again,
which would be a bigger number,
and we eliminated all of them.
so we want to move the left pointer.
so we move the last point to the right.
now.
so five plus eight and um five per cent is going to give us thirteen.
the number that we want.
and that is our answer.
and we just have the left pointer in the right pointer,
that is constant space.
we all use an extra hash table or anything.
and in terms of time,
we actually run in oath and win,
and the actual lake algorithm that we just described here with the left and right pointers runs an oath and time,
because at the most,
you know,
and eventually they get equal to each other.
and in total,
you know,
once or twice.
and so that.
convert is to owe them time.
therefore we can write the time to be oh,
of an and.
and the space can be written as o of one,
which is constant space.
so this is a really cool way to solve this algorithm.
once again,
i apologize for having forgotten about it.
some questions,
so definitely check it out if you want to see how it works.
and in the context of that question,
which is a bit more complicated.
walk through of all these solutions.
all right.
some function to find it takes an an array of distinct integers and an integer value,
representing the target sum.
which is going to run in of n squared time,
where n represents the length of the array.
for that solution,
all we have to do is literally implement two,
four weeks,
it will say i and rain um when of array minus one we want to go all the way to the before last value in the array.
and then we can say we can say current num,
or rather,
first numb kind of declare our first variable is going to be equal to array of i,
and then we can say four j in range.
i plus one one of array.
here we can,
you know,
we can say,
second,
num is going to be equal to array of the j.
right?
and then we say,
yes,
first,
numb plus second equals target some,
and just return an array of first and second,
none.
then at the end we can here return an empty array.
statements in the double four loop.
so that is the first way of falling this problem,
here is just for readability purposes.
and then at the end were returning either an empty array or an array of two values.
all right now,
the way that we really covered in the conceptual overview is uses the hash cable.
this is going to be the different,
so cumbersome array target,
some has the same two parameters.
the dictionary here in python,
or a javascript object.
and work is going to call it a numbs ford for numbers.
four,
numb in array.
minus num is in our numbers.
have cable.
now,
what is target,
some minus snub?
right,
in the conceptual overview that we called why this is basically are equation.
you know,
why equals target some minus x?
that was the equation that we cover in the conceptual overview.
so if target,
some minus numb,
which is the y value is present in our numbers.
hash table,
well then just return target,
some minus num comma.
num,
okay.
otherwise,
a numbers of numb is going to be equal to true.
otherwise we just store our current number in the hash cable and we can restore it as true or whatever you want to put here.
right,
i think through makes the most sense here.
and then at the end,
if we never hit this return statement,
and so here,
by the way,
it might be for readability purposes,
in it might be better to declare you know potential potential match equals target some minus numb.
and then here we can and have,
replace target,
some minus numb with potential match.
this is going to run in o of an end time,
not and squared time.
but it will also run in oven space.
so i hope this video was helpful.
i hope it taught you um how to solve this algorithm.
and really,
i hope it show you how you can use hash cable to your advantage.
oftentimes hash table will make your algorithm use up a bit more space,
but run faster and more efficiently,
especially in more complicated algorithms that might use of space no matter what,
in which case,
but will actually help you from a time point of view.
all right,
for this video,
alright.
so the video is not over yet.
we still have this third solution that i mentioned earlier in the conceptual overview to implement in code.
right?
but at the very beginning,
our built in python,
sorting function um and assume,
or hope,
rather,
that it uses an optimal sorting algorithm like,
quick,
sort,
merge,
sort and runs in an oven log n time where n is the length of the array.
and so then we can initialize our left pointer to be equal to zero.
the first value in the array and are right pointer to be equal to the final value in the array or the final index in the array,
one over a minus one.
so then we can have a while loop,
and we can say wild left is less than right for,
right?
or while there,
you know,
one of them is not while the left one is not pass the right one.
um the current sum is going to be equal to array of left,
plus array of right,
and the current sum is equal to what?
parentheses.
here is the current sum is equal to the target sum.
then we could,
we can just return um left and or rather array of left and array of right,
right,
the two numbers that we have,
and then we can say l s.
and here let me make a bit of space,
l,
with a current sum,
is less than the target sun.
if our print son is less than the target sum,
then we want to increase the left pointer so we can say left,
plus equal to one.
and then if the current sum is greater than target,
some right,
plus equal or right side,
a minus equal to one,
because then we want to move the right pointer to the left,
my one position,
otherwise we can just return the and theory if we get out of this while loop,
without having hit this,
twenty eight and without having returned you know,
two numbers.
the target sum,
and we were turned the empty array.
so this algorithm is going to run in o of n log n time,
so you can kind of see that um the space complexity here is as good as the first algorithm,
with the double four loops,
better than the one with the hash cable,
and the time complexity is better,
definitely better than the one with a double four loops,
but a bit worse than the one with the hash table.
so.
here,
if you were in an interview and you came up with all three of these solutions,
talk with your interviewer about the trade offs,
you know,
you value space more than a time in which casey use this last solution.
otherwise you use probably the solution with the hash cable if you valued time the most.
so i hope this video was informative for the second time around,