1
00:00:00,660 --> 00:00:04,050
Hi everyone, we have successfully coded the second method.

2
00:00:04,050 --> 00:00:10,080
Now let's quickly take a sample input deaf, deaf and walk through what's happening over here.

3
00:00:10,080 --> 00:00:13,320
Initially we create an empty array over here.

4
00:00:13,320 --> 00:00:14,400
New string to compare.

5
00:00:14,400 --> 00:00:16,290
So this is an empty array in this case.

6
00:00:16,290 --> 00:00:22,980
And we traverse the given string this one from uh right to left in this direction right.

7
00:00:22,980 --> 00:00:27,990
First we take the rightmost character and we insert it into the empty array.

8
00:00:28,140 --> 00:00:30,060
And we keep doing that again and again.

9
00:00:30,060 --> 00:00:30,240
Right.

10
00:00:30,240 --> 00:00:31,890
We are moving the pointer to the left.

11
00:00:31,890 --> 00:00:36,810
We take one character at a time and insert it into the empty array.

12
00:00:36,810 --> 00:00:38,730
So that's what we are doing over here with Dot.

13
00:00:38,730 --> 00:00:40,380
Push right with this the.

14
00:00:40,380 --> 00:00:42,450
And remember this is a constant time operation.

15
00:00:42,450 --> 00:00:46,470
And at the end we are joining this and making it into a string.

16
00:00:46,470 --> 00:00:46,860
Right.

17
00:00:47,010 --> 00:00:48,240
That's happening over here.

18
00:00:49,220 --> 00:00:49,640
Right?

19
00:00:49,640 --> 00:00:55,160
So once we have done that, we are just checking whether this is the same as the given string.

20
00:00:55,160 --> 00:00:57,080
Now in this case it's not the same.

21
00:00:57,080 --> 00:01:00,110
Therefore we will return false and we have our solution.

22
00:01:00,110 --> 00:01:04,910
Now we we've seen that this is this has a time complexity of O of n.

23
00:01:04,910 --> 00:01:06,470
Now there are two things.

24
00:01:06,470 --> 00:01:11,360
First of all we have this for loop over here which is an O of N time operation.

25
00:01:11,360 --> 00:01:11,720
Right.

26
00:01:11,720 --> 00:01:12,470
Why is that so?

27
00:01:12,470 --> 00:01:15,230
Because we are traversing the given string once.

28
00:01:15,230 --> 00:01:22,640
Now remember we are pushing each character to the empty array and then to first it's empty and later

29
00:01:22,640 --> 00:01:23,360
on it's not empty.

30
00:01:23,390 --> 00:01:25,250
We are keeping on pushing characters to it.

31
00:01:25,250 --> 00:01:30,890
But the interesting thing over here is pushing an element into an array is a constant time operation,

32
00:01:30,890 --> 00:01:31,970
so it's not costly.

33
00:01:31,970 --> 00:01:35,870
So the net time complexity of this solution is O of N.

34
00:01:35,870 --> 00:01:41,900
And we have seen that the space complexity of this solution is also O of n because we are creating this

35
00:01:41,900 --> 00:01:44,540
empty array, and then we are changing it into a string.
