Hi, everyone.
So in this video, we will be writing the code for this problem, using the mathematical approach.
So first let's rename the variable or rename the edit name.
So let's name it array or let's name it victory, or we can also rename it Doueiri.
Yeah, it seems fine.
Right.
So the two equations was this was our first one.
That is the actual sum, that is the Edison, Brait, Edison and some from one to N is basically our
A minus B and then we have one more question, which is some and this was the Edison that is actual
sum.
And we need to take square of all the elements minus some square of all the elements.
And this was our E squared, minus B scrapyard was A minus B and A plus B, right.
So let's try to find out this value and this value.
Let's do that.
So let's take the variable sum.
So this is basically our actual sum, right?
So let's rename two or not.
Somebody will let this complete value.
This complete value, I am denoting this complete value with some and this complete value, I am denoting
this value as square some.
Right, so let's try to find out some answers.
And so initially it will be zero, obviously, and obviously what will be the square?
Some square, some will also be easy to find.
And let's take one variable.
Them, right, so now let's it over the area.
We need to hydrate, so I call zero.
I less then added retard size I plus plus.
So what is this temp variable?
This temp variable is nothing but the eighth element of the adding.
Fine now for finding out the value of some what you will do, so for finding out some the actual some
will get incremented by the terrorism and will get the by this Anderson.
Right.
So basically what I want to say it is in this some.
I will add the revenue which is up, and from this sum, I am going to decrease the value and the value
which I'm going to decrease is basically a plus one, right.
This is a what we need to do.
We need to decrease the value once sorry, one plus two plus three plus tail end.
And we need to take decrement rate so the sum will decrease rate negative.
So I'm decreasing the value and the value of a zero I need to one.
So that's a plus one.
Right.
And we will do exactly the same.
Four-Square some.
So Four-Square, somebody will do
this is our square some and we will add the square.
So that is.
Temp in the temp, we need to take this square.
Similarly, we need to decrease the values to square some minus equals to this is our I I plus one into
two plus one.
Right.
And this value may overflow.
So let's do one thing.
Let's typecast these values into Longlong.
Right.
These are like vandevelde multipoint so their values might overflow.
So to avoid overflow, to avoid integer overflow, let's typecast these integer values into long long
fine.
So when we will come out of this loop.
So I have two values now.
I have two values.
Now I know the value of some.
And I know the value of square some.
So let's try to find out if we have the value of A minus B, let's try to find out A plus B, so for
finding out plus B into Divided Square, some by E minus B and C minus be some sort of square sum divided
by a sum will give you A plus B eight.
So let's take another variable long, long, and this value is A plus B, so what should be the variable
name, the variable name, let's say A plus B or what should be the variable name?
Some maybe.
Made the video.
Maybe that is A plus B, so this value will be us square some.
Some divided by your son, right?
So now you have the value of A plus B and what is this some this sum is nothing.
This is the value of A minus B.
And now if we will add this, if we will add some and we will add some ebby, so you will get the value
of a rate so integer that we need to find out this is nothing.
But you will add some plus you will add some AB.
And divided by two rate Ed, divided by two.
So once you have the value of a what will be the value of B, so value of B will be so the value of
B will be.
So if we will see this is A plus B, right.
You know, the value of it.
So what put it here, that is some A, B minus E, right.
So B is nothing but simply you are some A, B minus A.
So you have the value of A and B and we need to return back to.
Right.
The return type is basically you need to return and add a vector and let's say answer and we need to
insert A and B so on.
Sadaat push back.
You know, which is coming twice and the Vinoba which is missing,
right, and we will return our answer.
So let's try to test and if everything works, fine, then we'll submit.
OK, so they should be spelling mistakes.
They should be square some.
Yep, so let's try to submit now.
So, yeah, our solution is working fine.
Right, and now let's discuss their time in the space complexity for this, so it's very simple and
very obvious.
So what is our time complexity?
So we are trading over this area, right.
And we are doing constant work inside.
So a precise number of elements and certain complexities big often if we talk about the space complexity,
we are creating fewer tables here and there.
And this is vectoring dancer.
So the question is asking us to return vector and this rectories of size only two, it will contain
only two elements.
So we can say the space complexity is constant.
Right.
So this is the time and the space complexity.
And this is much better than the map approach.
In case of map, that time was when and the space was also big off.
And so we are able to reduce space.
So this algorithm is better than the map when approach.
Right.
So this is all about this device.
I will see you in the next one.
Thank you.