Hi, everyone.
So in this video, we are going to solve this question, Jack, palindrome, and we need to solve this
question using recursion.
So you know what this palindrome palindrome is, if you will read from left to right or if you read
from right to left, they will be equal, for example, one, two and one.
So read from left to right or from right to left.
They are saying so one, one, three, three, two and two.
So read from left to right.
One, three, two, two, three, one.
And read from right to left.
One, three, two, two, three, one.
So this is a palindrome.
This is also a palindrome.
One, two, three.
This is not a palindrome from left to right.
It is one, two, three.
From right to left, it is three to one.
So this is not a palindrome.
You have to write a function, they're able to function flyball, so you have to tell whether it is
a palindrome or not, so it will return.
True or false?
The name of the function, let's a palindrome.
It will take ideas and put it will take starting next and the next.
So we need to solve this question using an equation, so how against all this question?
So it's very simple.
This is already.
So I'm giving it I'm giving the starting next, I'm giving the end index, so this is the start index
initially zero.
This is the index which is initially and minus one.
So first of all, I will check.
So these two elements should be same.
So if these two elements have seem so, if this element and this element are same, then my work is
done, I will call occasion for Destry, I will call for this very simple.
So Rákosi will give me where this small area is palindrome or very small.
Small.
It is not palindrome.
And simultaneously, if this is my last palindrome, I will return.
True, if this small area is not palindrome, then the bigger will also not be a palindrome.
OK, so if the smaller is palindrome, then bigger is also palindrome because we already checked for
these two elements.
Right?
So let's rewrite the code.
So, Intisar, not in danger.
There will be.
The name of the function is Jack Palindrome.
I will take areas and but you can take a digit area.
You can correct.
It's your choice.
I will take this starting next.
I will take the ending, Alex.
So first of all, the base case, what is the base case, so base cases, if it is empty, see if it
is empty, if it does not exist, so if it does not exist, in normal case, START is here and is here.
So in normal case, status, Lieutenant, in normal situation, but if the area is empty, then start
will be cleared.
And if that is empty.
So if that is and start is going to end, so in that case, I will return to empty, it is a palindrome.
If that is empty and yet it is said to be a palindrome.
OK, so empty, it is a palindrome.
Otherwise what we need to do.
So what we need to do, this is our very.
So this is the starting starting next.
This is the end, the next and then what I have to do, I have to compare these two values.
So if these two values are equal start and they are equal, I will call that equation for this small
area, otherwise I will return false.
It is very simple if the start value and the end value, so if they are equal.
I will call Dacogen, so I will do something in the aspart.
I will return false if they are not equal, so if they are not equal, I will return false.
Otherwise I will do something.
And what I will do so I will collocation.
I will call occasion for deciding.
So the equation will tell me whether this is a palindrome or not.
So if this area is not palindrome, so the question will return false.
So if the smaller is not, then bigger, it is also not palindrome.
So I will likely return false.
So I have this.
Mollari is a palindrome, so the question will return.
True.
So if this is palindrome and I already checked that these two elements are also equal, so bigger is
also a palindrome.
So I will return.
True.
So whatever the result recursion is giving me, I am directly returning that result.
OK, so if it's true, I will return to Africa.
That's what I will return false.
So I just need to return the value which recursion is returning me.
So how we can call for this.
So for this idea, this is the starting index.
This is the starting next for this small area.
And this is the ending index for the small area.
So starting indexes basically start plus one and then index is basically and minus one.
So let's call.
So I need to check whether the small arrest or not I will pass so far small at the the next is a start
plus one for the small at the end being next is and the minus one and minus one.
And whatever the result this function will give, it will return it to Werfel's value.
So I will likely return that value.
So let's create one error here in Digerati.
Ready.
So let's say the first element is one, two, three, then again, three, two and one.
So this is a palindrome.
Let's call the function called palindrome.
Starting next is zero.
What is the last index, so the sizes is one, two, three, four, five and six sizes, six elements
is six.
So the last Nexus five.
So I am calling the function room six, so starting next to zero and the next is basically and minus
one, which is six.
Minus one, that is five.
So this check function will return to.
And I am painting so true, this one will be printed if it returns false, false, zero printed since
this is a palindrome, so the output will be one.
So output will be one.
Harpreet is coming out driven because it is a palindrome, and for example, if it is Ford, let's make
it Ford.
So now this is not a palindrome.
So output will be zero.
So our party's coming out with zero simple, let's take one more case.
So this is basically the even number of elements, let's take a number of elements commentary and the
last index will now be six now.
So this is a palindrome.
OK, this is a palindrome.
One, two, three, four, three, two, and one.
So read from left to right or from right to left.
It is a palindrome.
So this is the starting next zero.
This is the ending index, which is six because the total number of elements is seven.
So output will be one through.
So one minister, this is a palindrome.
That's why I am getting one.
So that's how everything is working, so let's try in one example.
So let's take one example.
Right.
So let's take this example.
I have one.
So two, three, four, three, two and one.
So this is the start.
This is the end.
Kick start the article, so start and the article, so call on this, Mollari.
So this is already it is containing all the elements one, two, three, four, three, two and one.
So this is us start.
You are doing start plus one.
OK, start will move ahead.
You are doing an A minus one so and will move back.
So this is your end now check.
So start and they are equal.
So if they are equal, call on this Mollari.
So this is already the elements are one, two, three, four, three, two.
And when we are passing the completely OK we are passing completed.
So this is our start.
This is our start and this is our end start plus one and minus one.
OK, start listening to minus one, check three three.
They are same so three and three the same.
So again collocation on this merletti.
So colocation.
We are passing the completely we are just changing the starting point, the.
So start plus one and a minus one and minus one, so start here and is here, so four is equal to four.
So I will call again on the three.
So I'm calling again on the.
The elements are one, two, three, four, three, two and one.
So START will move ahead and will move back.
So we start this here and here, you can see start plus one and minus one.
So start will move.
Forward and will move backward, so now we will hit the best case.
So what is the best case?
Start is bigger than any, so start is now bigger than that.
So in that case, I will return to.
I will return to.
And you can see whatever value we're getting from because we are directly returning, so I will return
true.
I will return true, I will return true.
I will return true.
So this is a palindrome.
I am getting through.
I will print one.
So let's take one example.
When this is not a palindrome, when this is not a palindrome, let's take that example.
So this is one, two, three.
I have four, then two and then one.
So this is not a palindrome.
This is the start.
This is the end start.
And they are equal.
So called recursion and bosnich complete and update the value of starting.
And so start plus and minus and start will come here and will come here.
This is a start.
This is and compared to the two.
So they are equal collocation.
If they are equal we will call recursion and it will pass the computer, we will pass the whole array
and we will change the values of starting in.
So START will move ahead and will move back.
So this is your start, this is your end.
So now you can see start and end the article, so you will return false.
You will go in the spot and you will return false.
So you will return false.
So basically for this very dirty question we are getting for this area, basically that equation is
returning false.
OK, that equation is giving me false.
So the equation is giving false.
So whatever value you're getting from the equation, you are likely returning.
So I will return false and I will return false.
So for false, I will print zero.
So that's why zero printed for this area.
So I hope you understood this question.
So this is it from this video.
I will see you in the next one.
Bye.