1
00:00:00,770 --> 00:00:03,320
Hi everyone, let's do this question.

2
00:00:03,320 --> 00:00:04,670
You are given a string.

3
00:00:04,670 --> 00:00:08,960
Write a function to check whether the string is a palindrome or not.

4
00:00:08,960 --> 00:00:15,230
Now when you're doing this in an interview, feel free to ask any clarifying questions you have now.

5
00:00:15,230 --> 00:00:20,120
Probably you could ask what if only a single character string is given?

6
00:00:20,120 --> 00:00:21,920
Should I treat it as a palindrome?

7
00:00:21,920 --> 00:00:23,990
Now again, remember what's a palindrome?

8
00:00:23,990 --> 00:00:27,110
It's a string that reads the same forward and backward.

9
00:00:27,110 --> 00:00:33,200
For example, if you have the string a, b, c, b a right now forward.

10
00:00:33,200 --> 00:00:34,310
This is how it reads.

11
00:00:34,310 --> 00:00:36,380
Now if you read it backward also, it's the same.

12
00:00:36,380 --> 00:00:38,090
So that's what we call a palindrome.

13
00:00:38,090 --> 00:00:41,540
Now even if you don't know that you can ask that also in the interview.

14
00:00:41,540 --> 00:00:46,370
So feel free to ask any clarifying questions so that you understand the question very well.

15
00:00:46,370 --> 00:00:47,960
Now for this question.

16
00:00:47,960 --> 00:00:50,810
Is a single character string treated as a palindrome?

17
00:00:50,810 --> 00:00:53,210
Let's say that the interviewer responds yes.

18
00:00:54,190 --> 00:00:54,730
All right.

19
00:00:54,730 --> 00:01:00,310
Now, another question that you could probably ask is what should happen if the string input is empty?

20
00:01:00,340 --> 00:01:05,380
Now let's say the interviewer replies, you can assume it's a non empty string.

21
00:01:05,380 --> 00:01:09,910
So that means that only a non empty string will be passed.

22
00:01:09,910 --> 00:01:10,540
All right.

23
00:01:10,570 --> 00:01:15,040
Now another question that you could ask is what should be the output of the function.

24
00:01:15,490 --> 00:01:19,390
Now in this case we can say that let the output be true or false.

25
00:01:19,960 --> 00:01:25,990
So another question that you could ask is should lowercase and uppercase alphabets be treated as different.

26
00:01:25,990 --> 00:01:29,380
Or should they be treated as the same like a and a?

27
00:01:29,410 --> 00:01:33,640
Now let's say that the interviewer responds and says treat them differently.

28
00:01:33,640 --> 00:01:34,210
All right.

29
00:01:34,210 --> 00:01:37,630
By this point you have got a good understanding of the question.

30
00:01:37,630 --> 00:01:40,450
Now let's proceed and write some test cases.

31
00:01:40,450 --> 00:01:43,630
Now remember test cases are just various inputs.

32
00:01:43,630 --> 00:01:47,920
And what output is expected if those inputs are given.

33
00:01:47,920 --> 00:01:51,130
Now in the interview you can take the help of the interviewer.

34
00:01:51,130 --> 00:01:55,990
You can ask him or her is it okay if we come up with a few test cases together?

35
00:01:55,990 --> 00:01:57,280
So that's a good practice.

36
00:01:57,280 --> 00:01:58,630
So you can always do that.

37
00:01:58,630 --> 00:02:01,240
Now let's go ahead and make some test cases.

38
00:02:01,240 --> 00:02:03,520
Let's say the input string is Malayalam.

39
00:02:03,520 --> 00:02:05,050
So this is my mother tongue.

40
00:02:05,050 --> 00:02:08,830
And you can see that it reads forward and backward the same.

41
00:02:08,830 --> 00:02:09,100
Right.

42
00:02:09,100 --> 00:02:12,490
So if this is the input the output should be true.

43
00:02:13,030 --> 00:02:15,070
Now what if the input is AA.

44
00:02:15,400 --> 00:02:17,320
In this case also it's the same right.

45
00:02:17,320 --> 00:02:19,060
So the output has to be true.

46
00:02:19,090 --> 00:02:22,660
Now what if the input is just a single character string.

47
00:02:22,660 --> 00:02:24,460
So the output has to be true.

48
00:02:24,460 --> 00:02:26,410
So we clarified this from the interviewer.

49
00:02:26,410 --> 00:02:28,480
And what if the input is aa.

50
00:02:28,510 --> 00:02:30,700
Now this is lowercase and this is uppercase.

51
00:02:30,700 --> 00:02:33,130
So these are to be treated differently.

52
00:02:33,130 --> 00:02:36,640
So this is to return the answer as false.

53
00:02:36,640 --> 00:02:39,040
So we've got a good understanding of the question.

54
00:02:39,040 --> 00:02:45,010
And we have written out test cases to ensure that the interviewer and we are on the same page.

55
00:02:45,010 --> 00:02:49,750
And we also understood any edge cases that we need to take care.

56
00:02:49,750 --> 00:02:50,200
Write test.

57
00:02:50,320 --> 00:02:55,480
Writing test cases helps you identify whether you have missed any particular edge cases or particular

58
00:02:55,480 --> 00:02:58,900
inputs for which you need to take care that the output is correct.

59
00:02:58,900 --> 00:03:02,050
Now let's go ahead and see how we can solve this question.
