Hi everyone, we have successfully coded the second method.
Now let's quickly take a sample input deaf, deaf and walk through what's happening over here.
Initially we create an empty array over here.
New string to compare.
So this is an empty array in this case.
And we traverse the given string this one from uh right to left in this direction right.
First we take the rightmost character and we insert it into the empty array.
And we keep doing that again and again.
Right.
We are moving the pointer to the left.
We take one character at a time and insert it into the empty array.
So that's what we are doing over here with Dot.
Push right with this the.
And remember this is a constant time operation.
And at the end we are joining this and making it into a string.
Right.
That's happening over here.
Right?
So once we have done that, we are just checking whether this is the same as the given string.
Now in this case it's not the same.
Therefore we will return false and we have our solution.
Now we we've seen that this is this has a time complexity of O of n.
Now there are two things.
First of all we have this for loop over here which is an O of N time operation.
Right.
Why is that so?
Because we are traversing the given string once.
Now remember we are pushing each character to the empty array and then to first it's empty and later
on it's not empty.
We are keeping on pushing characters to it.
But the interesting thing over here is pushing an element into an array is a constant time operation,
so it's not costly.
So the net time complexity of this solution is O of N.
And we have seen that the space complexity of this solution is also O of n because we are creating this
empty array, and then we are changing it into a string.