1
00:00:00,720 --> 00:00:01,680
Hi everyone.

2
00:00:01,680 --> 00:00:05,100
Let's now code together the first method that we discussed.

3
00:00:05,130 --> 00:00:07,560
Now for this we are going to create a function.

4
00:00:07,560 --> 00:00:10,320
Let's call it is palindrome check.

5
00:00:11,110 --> 00:00:14,080
And we're going to pass in a string to this function.

6
00:00:14,080 --> 00:00:20,020
Now what we're going to do is we're going to create a new string from the back of the given string.

7
00:00:20,020 --> 00:00:20,350
Right.

8
00:00:20,350 --> 00:00:25,210
We'll take character by character from the given string and insert it into the new string.

9
00:00:25,210 --> 00:00:26,200
So let's do that.

10
00:00:26,200 --> 00:00:29,170
For this let's create a empty string.

11
00:00:29,170 --> 00:00:33,580
So let um new string.

12
00:00:34,590 --> 00:00:36,150
To compare.

13
00:00:36,330 --> 00:00:38,460
So I'm just calling it new string to compare.

14
00:00:38,490 --> 00:00:40,110
Now this one is empty.

15
00:00:40,260 --> 00:00:48,150
Now we're going to have a for loop for let I is equal to string dot length minus one.

16
00:00:48,150 --> 00:00:51,630
Because we want to go from the end of the input string right.

17
00:00:51,630 --> 00:00:56,700
And I greater than equal to zero I minus minus.

18
00:00:57,000 --> 00:01:04,800
And as we traverse the input string from back to the front, we are going to take one character at a

19
00:01:04,800 --> 00:01:07,620
time and append it to the new string.

20
00:01:07,620 --> 00:01:12,390
So let's do that new string plus equal to.

21
00:01:13,480 --> 00:01:15,070
String I.

22
00:01:16,830 --> 00:01:17,190
Right?

23
00:01:17,190 --> 00:01:20,760
So at the end of this we would have created a new string.

24
00:01:20,760 --> 00:01:26,880
Now all we need to do is we need to check whether this new string is the same as the given string.

25
00:01:26,910 --> 00:01:31,200
Now if it is the string same, then we will return true, right?

26
00:01:31,200 --> 00:01:33,060
So we can return true.

27
00:01:35,520 --> 00:01:42,750
And if it is not so, if if it's not true, then we can just return false.

28
00:01:43,970 --> 00:01:44,240
All right.

29
00:01:44,240 --> 00:01:47,990
So even over here also, I could have just written because it's just one statement.

30
00:01:47,990 --> 00:01:49,760
So let's just make it smaller.

31
00:01:50,590 --> 00:01:54,610
Now it's one and the same, so I'm just making it smaller.

32
00:01:54,610 --> 00:02:00,460
So we are going to return true if they are the same and if it's not the same, then we are going to

33
00:02:00,460 --> 00:02:01,330
return false.

34
00:02:01,330 --> 00:02:04,300
And that's the function that we have written.

35
00:02:04,330 --> 00:02:04,660
All right.

36
00:02:04,660 --> 00:02:05,830
Now let's test it.

37
00:02:05,830 --> 00:02:07,930
For this I'm creating a string.

38
00:02:07,930 --> 00:02:10,660
So let this A be equal to.

39
00:02:11,230 --> 00:02:13,450
Let's say the given string is ABC.

40
00:02:13,750 --> 00:02:18,850
Now let's pass it and console log what we get to our function.

41
00:02:18,850 --> 00:02:20,200
So is palindrome check.

42
00:02:20,200 --> 00:02:21,310
And we are passing a.

43
00:02:21,310 --> 00:02:21,880
All right.

44
00:02:21,880 --> 00:02:25,330
So let's now see what we get when we run this.

45
00:02:27,140 --> 00:02:31,040
So when I run this, I get false because ABC is not a palindrome.

46
00:02:31,040 --> 00:02:33,410
What about if it's ABC ba?

47
00:02:33,890 --> 00:02:36,320
So and now I get true because it's true.

48
00:02:36,320 --> 00:02:36,650
Yes.

49
00:02:36,650 --> 00:02:37,850
This is a palindrome.

50
00:02:37,850 --> 00:02:42,380
Now what if it's a single character string I get true.

51
00:02:42,380 --> 00:02:42,740
Yes.

52
00:02:42,740 --> 00:02:43,820
So that's good.

53
00:02:44,330 --> 00:02:46,790
And what if I have small A and capital A?

54
00:02:46,790 --> 00:02:52,640
I get false because in the clarification we got the clarification that these are treated separately.

55
00:02:52,640 --> 00:02:54,890
So yes we have coded our first solution.

56
00:02:54,890 --> 00:03:00,530
Now let's take a sample input and see what's actually happening over here.
