Hi, everyone.
So today we are going to solve this question, valid palindrome, too, so this question is present
only told.
OK, so let's see.
So this is the question really boils down to now we can read the statement here.
So the input will be a string as and we have to delete at most.
One character we can add makes delete one character and then we have to tell whether we can make palindrome
or not.
OK, so basically so the input will basically be a string.
OK, and the output will be a boolean value, true or false?
And our question is basically from the string, we can delete zero characters, basically do not modify
the string or we can delete one character.
And then we have to tell whether the leading one character can result, can make the string into a palindrome
or not.
OK, so you can see the example here.
So in this case, ABC.
OK, so ABC now, this is already a palindrome.
OK, so we are not deleting any character.
So basically we are deleting zero characters and the output is true.
OK, so this is a palindrome.
Now see this example, ABC.
OK, so we have ABC now.
Obviously this is not a palindrome, but if it will delete the character, see if we will to see, then
it will become ABC.
And this is a palindrome.
So basically we are deleting one character and we are getting a palindrome.
So in this case, I will return.
True.
OK.
So at Max you can see here at Max we can delete zero one characters.
OK, so at most we have to delete one character.
OK, so in this case, we are not building any character, and in this case we are deleting one character
to obtain the palindrome so the output will be a draw.
OK, now there can be many examples like, for example, ABC.
OK, so if you will delete zero characters, obviously this is not a palindrome.
If you will delete one character.
So let's suppose you can delete it then.
Also, it is not a palindrome.
If you will see then also it is not a palindrome.
You delete be then also it is not a palindrome.
So basically the output for ABC listing will be false because deleting zero or one character does not
result in a palindrome.
OK, now let's take some one example.
For example, I have this string Abebe.
OK, so this is my input now.
I can delete correctly, so it will become a baby, so is it a palindrome?
No.
So here I deleted one character.
Now we can also delete this character, for example.
So it will become a verb then.
Also, it is not a palindrome.
If so, basically they can be like many cases of deleting one character.
But finally, all these are not palindrome.
So in this case, our output will be false.
OK, so for input, Abebe, our output will be false because deleting one character cannot make the
string into a palindrome.
OK.
Now let us consider this example, Abebe.
OK, now if I delete, if I'm deleting led to this character.
So it will become baby.
Now this is a palindrome.
So the output for the string ab is true.
OK, because we can delete one character to get a palindrome.
In this case you can also delete characters like this one.
OK, then it will become a B.A. and this is also a palindrome.
OK, let's take one more example.
So let's say you have the string A, B, B, C, D, and B, OK, so in this case, if I had believed
this character C.
Then what will happen, so it will become A, B, the the B, so basically it will become a palindrome.
OK, so the output for this string will be through.
OK, now let's come to the question.
So how are we going to solve this problem?
OK, so how to solve this problem?
So basically, this is a very simple problem.
It is just a modification of the like checking palindrome problem.
OK, so it is just the modification of a palindrome problem.
Now let's see how we can solve this problem.
So basically, let's take an example.
So what we will do.
OK, so let's take an example, let's take a small example first so I have this string ABC and let's
say we have B and E, so this is already a palindrome.
OK, so I will keep two pointer start pointer and pointer.
OK, so start and they the article.
So move ahead, start will come here and will come here.
So startlingly equal.
Movahed So this is start and this is and start and end.
They both are equal so move ahead then finally start will become good and end and we can say this is
already a palindrome.
OK, so this is already a palindrome.
So we will return.
True.
Now let's see a case where I have to delete one character to obtain the palindrome.
So suppose I have this problem.
A baby.
OK, so this is my starting point, this is my end point.
Now, starting, they are not equal.
OK, so A and B, they are not equal.
So I have two cases, rather two cases.
Either I can delete A or I can be OK.
I can delete only one character.
OK, so either I can delete it or I can delete B academics.
I can delete only one character so I can delete more than one characters.
So let's suppose I am deleting it.
Then the string will become baby.
And if I were delete B then it will become a B.
OK, now I will check this string for the palindrome.
So this thing is palindrome.
So basically the output will be true.
So this jingled also coming out of a palindrome.
So the output is true.
OK, so in this case for the string ab what I will do, my output will be a true.
OK, now suppose the string was, let's say a, B, A and let's say the OK, so in this case again.
So this is my start pointer.
This is my end pointer.
So start and they are not equal.
So I have two cases.
Either I can delete it or I can delete the.
So if I am deleting a I am deleting it then it will become B ID or I can delete these.
So I am deleting the then the string will become a, b, a..
OK, so this is not a palindrome, so it is false and this string is a palindrome.
That output is true.
OK, so if I will delete the character D then the string will become palindrome.
So what I will do.
So my output will be true basically.
OK, so I will return true for the string early.
OK, so for the string ability, if I read the character D then the output is basically a palindrome.
OK, so our approach will be very simple.
So what.
So what we are going to do here is.
So suppose we have a very long string, let's say a B and finally, let's little Dabi and then we have
some characters and then again, we have, let's say, a day and let's see, OK, and these are.
So this is a very big string.
OK, so what will be our approach?
So our approach is going to be very simple.
I will keep 2.0.
So this is a start point.
This is an appointed.
So start and end the article.
So move ahead.
Start will come here and we'll come here, start and end the article to move ahead.
So this is my start and this is my end.
OK, so now here the start and end.
They are different.
OK, so B and C, they are different.
So whenever we will encounter this case, what will happen?
We have two situations.
We have two cases I can relate B or I can see.
So if I am deleting B, if I delete B, then I am writing from here, then my string will be this one.
OK, so.
I have to check this string, so if this string is a palindrome, then I will return to.
Now, the next case can be, I am deleting the correct policy, so if I were the correct WTC, then
my string will be this to this.
OK, so basically my string will be.
So starting from B and it will add and da da da.
OK, so basically here before the character, see so what I can do.
So if I am removing basically B start, so if I'm removing start, then I have to check the palindrome
from start plus one to end.
OK, so you can see and it's pointing towards the C so the first cases start to start.
So I have to check the string from start to end and if I'm deleting the end, so I am deleting and then
I have to check the string from start plus one.
So from start to end of minus one.
OK, so I have two cases, first cases, check the string from start plus one to end.
Now, the second case is so here I start.
OK, so I have deleted start and the second cases start to and minus one.
So here I am deleting and OK, so if either of them returns.
True.
If one of them returns true, then my output will be true, OK, if either dissident, true or dissident
true, my output will become true, either one of them should return true if both of them return false.
So if this is returning false and this is also returning false, then my output will be false.
Otherwise, the output will be true.
OK, so I hope you understood the question.
Now let us write the code, ok.
So let's then let's rename it to the name of this thing is a OK, so first of all, we are just writing
the simple palindrome function.
OK, so.
The start will be zero.
What will be and so it will be basically adult size, minus one.
OK, and no simple condition will start is less than articles to end.
So what I have to do so first of all, let's check.
So if.
If this start is not close to end.
So I start to question what I have to do, so I have to do some work I have to handle to get it.
OK, so two cases will be there.
Otherwise, I'm going to do start plus, plus and minus minus.
OK, and finally, if we are not building any character.
OK, so this thing is basically a palindrome.
String is.
Already palindrome.
So everything is already a palindrome then we can return to.
OK, now I have to handle two cases, so either delayed start so we can start, then I have to check
for.
I have to check for a string.
I have to check for string starting from start plus one.
The end and the second cases delayed the end, so delayed and then I have to check for the string.
So I have to check for the string starting from start.
Two and a minus one.
OK, so these are the two cases that we need to handle here, so let's try to function first.
So I am writing a function to bool.
Check now this check function is taking a string as input string, and it will take a start and end.
OK, so it is taking start and end.
Now, I will write this simple code, so we'll start this list in articles to end.
Would I have to do so if I start is not going to offend?
Then I congratulated Penfold's.
OK, otherwise, I am going to start plus, plus and minus minus, and here I am returning to.
So basically.
So basically what this function will do, so it will take a string as input, it will take the starting
point, it will take the ending point.
OK, so suppose I have a very long string.
So I have given this starting point and I have given the ending point so dysfunctional this function
will check this part of the string.
It will only this part of the string for palindrome.
OK, so if it is not a palindrome, if this part is not a palindrome, it will return false if this
part is a total return.
True.
OK, so this check function, it will not check the complete string.
It will only check a part of the string, OK.
It will only check a part of the string.
So what I have to do, so I have two cases, two first cases I'm calling the function check.
String is a and let's say I am deleting as so I will pass Astarte plus one to end.
Now the second case is let's call the check function.
String is a now.
I will delete the end.
So I'm deleting and so I will pass and minus one.
So if either of them, either this one or I did this one, if either of them returns true, I will return
to.
In the aspart.
I will return false.
So basically, what is the meaning here?
So when everything falls, that means after deleting one character.
After deleting one character, we are not able to make the string palindrome.
OK, so we are unable to obtain.
Apelin lobstering, OK?
So we after building one character, we are unable to obtain a palindrome string, then I can return
false.
OK, so this is very simple code and all this stuff called.
Knowledge summit.
OK, so our goal is working fine now let us discuss the time and the space complexity.
So basically the time complexities are there often and the space complexities big of one.
OK, so this is the time and the space complexity for this problem.
So if you have any doubt in this question, you can ask me, OK, so this question was very simple.
We are just like it is just a modification of the palindrome problem.
OK, simple modification of Ballenden problem.
OK, so if you have any doubt, please ask me, OK, thank you.