Hi everyone, let's do this question.
You are given a string.
Write a function to check whether the string is a palindrome or not.
Now when you're doing this in an interview, feel free to ask any clarifying questions you have now.
Probably you could ask what if only a single character string is given?
Should I treat it as a palindrome?
Now again, remember what's a palindrome?
It's a string that reads the same forward and backward.
For example, if you have the string a, b, c, b a right now forward.
This is how it reads.
Now if you read it backward also, it's the same.
So that's what we call a palindrome.
Now even if you don't know that you can ask that also in the interview.
So feel free to ask any clarifying questions so that you understand the question very well.
Now for this question.
Is a single character string treated as a palindrome?
Let's say that the interviewer responds yes.
All right.
Now, another question that you could probably ask is what should happen if the string input is empty?
Now let's say the interviewer replies, you can assume it's a non empty string.
So that means that only a non empty string will be passed.
All right.
Now another question that you could ask is what should be the output of the function.
Now in this case we can say that let the output be true or false.
So another question that you could ask is should lowercase and uppercase alphabets be treated as different.
Or should they be treated as the same like a and a?
Now let's say that the interviewer responds and says treat them differently.
All right.
By this point you have got a good understanding of the question.
Now let's proceed and write some test cases.
Now remember test cases are just various inputs.
And what output is expected if those inputs are given.
Now in the interview you can take the help of the interviewer.
You can ask him or her is it okay if we come up with a few test cases together?
So that's a good practice.
So you can always do that.
Now let's go ahead and make some test cases.
Let's say the input string is Malayalam.
So this is my mother tongue.
And you can see that it reads forward and backward the same.
Right.
So if this is the input the output should be true.
Now what if the input is AA.
In this case also it's the same right.
So the output has to be true.
Now what if the input is just a single character string.
So the output has to be true.
So we clarified this from the interviewer.
And what if the input is aa.
Now this is lowercase and this is uppercase.
So these are to be treated differently.
So this is to return the answer as false.
So we've got a good understanding of the question.
And we have written out test cases to ensure that the interviewer and we are on the same page.
And we also understood any edge cases that we need to take care.
Write test.
Writing test cases helps you identify whether you have missed any particular edge cases or particular
inputs for which you need to take care that the output is correct.
Now let's go ahead and see how we can solve this question.