Hi, everyone.
So in this video, we are going to discuss this question, finally, do some of the area using recursion
so we can easily solve this problem with the help of for loop and why loop.
But since we are learning recursion, so we will solve this problem with the help of recursion so that
the functional brainteaser, we will return to some of the.
And we will return at it.
We will get that as input and we'll get how many elements are there as input.
So we need to write the code for this function.
So I told you how we will use it.
So basically, we need to break our problem into smaller problem.
And there are two ways to break the area.
So the first rule of making this is what we will do.
So I will make the idea like this the second way of breaking the arrays.
I will break the array like this.
So what I will do, I will call Dacogen.
I have a qualification on this area.
So this they will return the records and will return me the sum of this 80.
So the question will be the some of the city of this military and what I will do, I will add this value,
so I will add this value of zero.
Simple now, a better way of solving this problem is basically I will call recursion on this very.
So the question will give me the answer, it will give me some of this small area and I will add this
value.
So this is and minus one, so I will add and minus one.
And that will be my final answer.
So very simple, right.
So first, let us write the code for this approach.
So the name of the function is the name of the function is some of Eddie.
So it will take ideas and put.
And it will take how many elements are there?
So basically this very simple.
If.
My area is empty, so if the size is zero, what will be the sum will be zero.
So the base case is very simple.
Now what we need to do.
So I told you.
Multivolume, I will call that equation.
So I will call dedication on this.
So this is a and this is a plus one and the number of elements and minus one, so the equation will
give me the answer to your question, will give me some of this small area and I will add this value.
So this value is Alpha zero, and that will be my final answer.
So what is my final answer?
They've done a zero.
Plus, all this dysfunction, some of Harry.
So the area which we want to give is this small area, so E-Plus one.
And the number of elements and minus one.
And that's all that we need to do.
So let's call this function out some of very.
We need to give Eddie.
And a number of elements, five.
So let's see.
So the output is coming out to 15.
So let's see whether 15 is right or wrong.
So if you will add one plus two plus three plus four plus five.
So this is the same as and when plus one by two, the value of it is five.
So five to six Vido, so Tatebayashi two is 15, or you can write like this.
So the output is 15 and 15 is the right output.
So our approach is correct, and now let's see how it is working, let's write a novel called.
So let's write a novel called So Let's take this example only.
So I have one, two, three, four and five.
The number of elements is five.
So the number of elements, the site is not zero.
So what I will do, I will collocation on this Mollari.
So I will call the on the smaller two, three, four and five.
The number of elements for so size is not zero, so call that equation the smaller I am calling the
equation.
I think this smaller and the number of elements, a number of elements, history and the elements are
three, four and five.
So, again, the size is not zero, so called the equation on smaller sizes, too.
So again, the size is not zero.
So call the equation smaller.
The size is one.
So again, the size is not zero.
So collocation on smaller.
So we'll call the ampitheater and size is zero.
So it is empty and size zero.
So if the sizes you know, I am returning zero, so this will return zero.
So now this is getting zero.
And what we are turning we are turning to some of the adding and plus 040.
So this is the only element of this is we will return zero plus five.
So I am returning five.
So now.
This area is returning fire, so this area is returning fire and I am getting zero, so I will wait
for and are done, so I will return four plus five.
So now this area is returning four plus five, which is nine.
So I will add eight four zero.
I will let you off zero and done so I will 80 and I will return to nine.
Plus three is 12.
So this area is returning to.
I will add 84 zero and I will return Sawtell plus two is 14.
So this area is returning 14 and I will add eight four zero.
I will add zero and return to 14 plus minus 15.
So I will return 15.
And 15 is the right answer for this problem.
Simple so that a way of solving this problem is basically what we will do.
I will call that equation on this area.
So starting this Arazi and a number of elements and minus one, so the question will give me the output
for this Osmolarity equation, will give me the sum and I will add the last element.
So aof and minus one.
And that will be my answer.
So let's write the code.
So, teacher, let's copy the name of the function, some of very.
To some of it, I will get it as input.
And I will get how many elements are there.
So this case will remain same.
If it is empty in the cities, you know, the sun will be zero, so I will return zero.
There is what we need to do, what will be our answer?
So our answer will be the last next the last two half and minus one, and we will call this function
some of the.
Some of little I will give the area and I will give the number of elements.
So now let's test dysfunctioning some of it to.
Output should be 15.
So the output is coming out to 15.
So this is also working.
And now let's see how it is working.
So what I'm doing is.
I am making my day like this.
I am calling the occasion for this.
So this is crazy and in number of elements isn't minus one.
So the question, will you give me the output for this area?
Because it will give me some indication, will give me some for this area.
And I am adding the last element.
So I am adding the value, I am adding this last element, and then I am returning the overall sum and
then I am returning the.
Let's take this example and let's see how it will work.
One, two, three, four and five.
So I have this.
One, two, three, four, five.
The number of elements is five.
So size is not zero, so I will call on the smaller.
I will call on one, two, three and four, the monofilament is four sizes, not zero.
I will call on the smaller one, two, three sizes, three sizes in order to also call on the smaller
one and to.
Number of elements is still so still the size is not zero, so I will call on the smaller.
So since the number of elements is one, it is not zero, so I will call on the empty address that is
empty and the site is zero, so the size of zero zero seven zero.
So basically this idea, what it will return the value which it is getting, plus the last value since
there is only one element.
So this is only the last value.
So zero plus one, I will return.
So basically this area is returning when the site is returning one.
And I will add the last value which is to so zero plus one three one plus two is three.
So I will return three.
So basically, this area is redundantly, this area is turning, I will the last value, so last year
values three, so three plus three is six.
So this area is returning six over the last 12 months where the lost value and return.
So last one is four six plus Foreston.
So this area is returning.
Then I will add the last value and return to last values 15 sodi the last values five five plus 10 15.
So I will return 15 and 15 is the right answer.
So that's how it is working.
So there is one more way we can write the code.
So currently what we are doing for example.
So if I want to pass this area, I am passing a plus one and I am giving N minus one, I am passing
eteplirsen and I am giving and minus one.
So instead of changing the area, what we will do so instead of passing only this area.
So one way of passing only this ad is basically changing writing like this, E-Plus one, the other
way is basically what we will take.
We will take our index.
So it will take the next.
The way he treated ordinary.
So if the value of Isarel so that means this starting next year, the value of zero, that means I am
passing the completely if the value of is one, that means I am passing.
I'm not passing this Rohter element.
I am passing the area starting from the first index.
If the value of I used to, I will pass the starting from index to.
If the value of iced tea, I will pass the idea starting from industry and so on, so basically if the
value of AI is ND, then I am passing the idea starting from index and starting from index and Nixon
does not exist.
That means this is the condition venue that is empty.
This is a condition for empathy, very simple.
I'm repeating myself, if the value of I zero, I will pass the starting from zero.
That means I am passing the completely.
So that is the meaning of equal zero means.
Pass the completed holiday.
Pass the holiday.
If the value of AI is one positive, starting from next one, if the value of I used to, I am passing
the idea starting from next to the value of history.
I am passing the area starting from index three.
So this is the condition for the whole area.
If the value of zero.
So this is the condition for the empty.
Very simple.
So let's write the code using this index.
So what I want to do, let's modify this code.
I want to modify this code.
Some of eighty three I will carry I will take a number of elements and I am taking one more, I am taking
I index I so what is the condition?
So this is a condition for Empty-headed, not a condition for Prairie's.
Eye becomes.
And so let's change the best case.
So, Batiatus, if I is, and that means my heart is empty, so I am returning zero otherwise, but
I will return, so I will call this function some of the three.
There's no need to change the.
The Namaroff elements will not change because I'm basically completely only the next will change, so
I plus one.
And similarly, this will be a.
And that's all that we need to do.
So now let's call dysfunction some of 83.
We need to pass the value of which is zero.
So let's see how it is working.
So first, let us run our file and let's see whether it will work or not.
So the output is coming out to 15, that means it is working.
OK, so.
This thing is working, I am passing the index and it is working, so let's see how it is working.
So the approach is very simple, see?
This is already.
The value of AI is zero, so this is a the value of a zero and the size of the arrays and so you are
taking I question no, then what they are doing.
You are retaining Elfy.
So this is Eddie.
So Afie is Disvalue.
So you are returning.
If I, if I use this value you are calling some of.
So we are calling recursion.
I am giving Eddie so I am giving the complete Eddie the number of elemental remains him because I am
giving this completely.
I am giving this complete attitude equation and not the similarity, so I am giving this complete addy
and not only this Mollari and then I'm giving a plus one.
So the value of 5.0 now it will become one.
So the value of I will become one.
So if so, for this area.
I am passing the computer.
I'm still passing the completely, but since the value of AI is here now.
And and is still the same, so and remains same, and we are passing the complete array, but we are
using a variable.
I do, I read over the area.
So next time what will happen?
You will pass the completely, but the value of five will become to show the value of.
I will become to.
This is the community will remain same.
Again, you will pass the completely and the value of I will become three, so the value of I, I am
using index.
So this is current index I am using next to irate over the area.
So let's put that in the school so that you can understand it better.
Let's write in for this example, one, two, three, four and five.
So my error is one, two.
Three, four and five.
Now, in this regulation, we are not breaking the ATM, we are passing the computer, but we are using
this variable and next you can see at any minute same number of human remains same.
So only this value is changing.
So let's see how we can use the value of a.
So I is at this position, so what is happening here, the number of elements is five.
So what we will do so I the value of let's illustrate the value of the value of zero zero zero is not
equal to five.
So you will call that equation.
So let's call that equation.
You will pass the completely.
I am passing the completed number of human remains same and I am passing the completely.
Only the value of I will change, so the value of I will become when we are passing plus one.
So one is not close to five again.
I will pass the complete editorialization number of elements to him, only the value of I will change.
So again.
The value of is not the cost.
And so I will pass the completely the value of these five.
The value of any number of him and I used three, so three is not close to five.
So again, I will pass the completely.
Remain the same.
The value of A for you can see we are passing the completely we are not changing any element because
since we are passing the total, the value of N will not change and we are just doing a plus one.
So I is not close to five, so I will pass the computer again.
One, two, three, four, five.
The number of elements are five and now the value of these five.
So now the value of is five, so I started from here, then I use here, then I is here, then I is
here, then I is here and now I becomes now I reaches here.
Simple.
So.
I used basically so this is zero one, two, three, four and five, so I reaches the next five.
So now you can see I end and they are equal.
So if I am, then they are equal.
I will return zero.
So this area will return to.
So I am getting zero and I am adding the value of elfy.
So what is I I is pointing I is standing here so I will add five in return.
I will add five zero and done so I will return five.
So I am getting five from this area.
I am getting five and I will if a what is if I if I is four.
So if I entertain, so I will return nine.
So no, and if I ended on whatever value you are getting, whatever value you are getting, and if I
ever done so and if I try and return so, I will return to.
So whatever value you are getting from Dacogen Guardian to and done so, I will return 14.
So whatever value you are getting from the Guardian ad elfy and if I understand if I is one so I will
return 15 and that's how we are getting 15.
So basically first we are getting first we are getting the sum for this area, then we are getting the
sum for this decided.
Then we are getting the sum for this area, then we are getting the sum for this area and finally we
will get the sum for the whole area.
We will return aof.
I will fight to this sum and we will return.
So that's how it is working.
So this index I so this approach is very useful and it is used.
This technique is very useful.
It is used at multiple places.
So what I want you guys to do is make banin paper and try to flatten this code, try to find out how
it is working.
So just give it a try and you will be able to understand it very easily.
So this is it from this video.
I will see you in the next one.