Hi, everyone.
So today we are going to solve this problem, reverse string.
OK, so the input will be basically a string.
So the input is a string.
And what we have to do, we have to reverse that string, OK?
So after reversing this string so our output will become all an edge.
OK, and similarly, if the input is this after reversing the string, the output will be only, the
output will be only and then bursting is broke, then output will be so be at 60.
OK, so basically we have to reverse the given string.
Now how we can solve this question.
So basically the first way.
So there are two ways to solve this question.
So the first way to solve this question is with the help of a string.
OK, so the first way is basically with the help of a stack.
Now alerted the input is hello.
So if the input is hello, so what we will do, so I will create a strike.
Stack of it will be a stack of characters.
OK, so I will have a stack of characters.
Now, what I'm going to do is so I would like to the string, so I am standing at what I will do, I
will push h e push inside the stick and or so push l l oh.
And finally the string will be over and this will be out and this will be the condition of the stick.
OK, so what I am doing, I am pushing every character.
So I am pushing every character of the string into the Hashmat into this deck.
OK, so Bush, every character in Lustick.
Now, what I'm going to do is I will pop every character.
So this was the first step.
Now the second step will be pop every character.
And that will be our answer.
OK, so Bob, so Popol.
Then l so and then L then E!
Then EJ.
OK, so the state will become empty, Stagg will become empty, and this is my reversed string.
OK, so this is my.
Reversed string.
So this was very simple.
OK, you can take one more example, also, suppose the string is very simple, Stinger's, you only
then what will happen initialised equilibrium between now let's say I did so a push a and then the string
becomes empty.
So after pushing I have to pop the character.
So after popping my output will be OK.
So this is very simple.
Now what will be the time and the space complexity.
So basically the time complexity is just we are taking over the string so it will be linear and the
space complexity is basically own because we will be creating a strike.
OK, so we are creating a strike and is basically the length of the string.
OK, and it's basically the length of the string.
So now let us write the code, OK?
So what do you have to do?
I have to create a stack of characters.
OK, so this problem is basically present.
Don't get caught.
OK, so you can see this is the same problem that we have discussed.
So what I'm doing here is.
I am creating a stack of characters and let's see the name of stackers ASG, so what I'm going to do
here, I have to write it over the string.
OK, so let's do it.
So I equals zero.
I listed as Nazis.
And libelous place, so I have to push every crack inside this tick.
OK, so what I'm doing here is push every character.
Decided to stick, so this was the first step, OK, that we have discussed.
So s-t, don't push, so let's change the name.
So I'm changing the name to be OK, so I consider a list the neo-Nazis so stagnant Bush aof I.
OK, so after the first step, now what we have to do.
So this is the second step.
We have to pop every character.
OK.
So I have to pop every character.
So let us trade so forward and DayQuil zero.
So how many correctible represented inside the state that will be incorrect.
And is basically the size of the vector.
OK, so I call zero I and Lot says.
I placeless.
So AFIC is basically stacked that top.
And then staggered artpop.
OK, and that's all so you can see here.
So basically, the return of the function is void, so they don't have to return anything and basically
what we have to do so you can see it is passed by reference.
OK, so the given vector is passed by reference.
That means we have changes inside the factory.
OK, so we have to rule changes inside the factory.
We have to modify the factory.
OK, so I'm here modifying the factory.
You can see here I am modifying Alphie is basically a startup and stagnant Bob.
So I had this line line number 15.
So at this lendee, that bell is reversed.
OK, so basically let us again, so if you want, you can, Driton, for example, of the string, let's
say each each.
So this is passed by defense.
So inside the stack.
So the first loop, Bush, every character.
So each e each.
Now the second step up, every character.
So Pop Edge, Bob and Bob, each one, for example, the ABC.
So this is initially stake is empty then Bush A, Bush B, Bush C then what I'm doing here is Popsie
put it here, probably put it here popi put it here.
And this is my answer.
c.B, we do not have to return anything okay.
We just have to change.
We just have to modify the given vector.
OK.
So now let us try to submit our gold.
OK, so our goal is working fine.
Now let's see the question again.
So the question is, is it we have to do using it using over an extra memory?
OK, so here we are using a stick.
So basically we are using big off and memory and we have to use constant and constant extra memory.
So how we can solve this question.
OK, so let's see.
So this is a very simple question, what you can do here is.
We will solve this question with the help of 2.0.
OK, so this is my input string.
I will take two pointer, start pointer and pointer married.
I'm going to do is swap start and end sep start pointer and pointer.
So what will become so all will come here.
It will come here then I will start plus plus and minus minus.
So this is my new start.
This is my new end again.
I am going to start and end.
So after stepping so this will become L, this will become E then start will come here.
And will come here, then what I'm going to do is I will strap, start and end.
So L will be swept with L and then start will come here.
And will come here, so when start becomes great, then and I will stop.
OK, so basically what we have to do, we have to step start and end point that only.
So let's take one more example.
So if the input is, let's say A, B, C, D.
OK, so what should be my output?
So the output should be the C, B, E, OK, so let's take two pointers.
So this is my start point and this is my end pointer.
SNAP, start and end.
So they will come here.
He will come here.
OK, now start will start plus, plus and minus minus.
So this is start, this is end, slap, start and end.
So it will become C, it will become B, then start, will become good then.
And so basically start will come here and will come here.
So then start is good and we will stop.
And this is my output.
OK, you can compare.
So our output is correct now.
Little bit of time and the space complexity.
So their time complexity will be linear.
OK, so this operation, this is question time over time and we are not taking any extra space so the
space will be open.
OK, so.
Time is linear and constant extra memory.
OK, so let us write the code.
So first, let us comment about this one.
Now we have to do I have to take two point us start point, which is at the beginning and end point,
which will be Iraq minus one.
OK, because the indexing starts from zero.
I would have to do so while start this list and articles to end.
I will do stepping operation to slap aof start, so basically strap is in belt function inside C++.
OK, so I am swapping start and end then what I have to do is start plus plus and minus minus.
And that's all.
OK, so let's try to submit.
OK, so our goal is working fine.
OK, now there is one inbuilt function also.
There is one elaborate function, which is called reverse.
OK, so we haven't built function reverse and I will pass it over to begin and end.
So it was a not begin nod and OK, and our vector will be reversed.
OK, so let's try to submit.
OK, so our Gore is working fine, so this reverse function, this is inbuilt function inside the C++.
OK, so it can reverse anything.
So here it is, reversing better.
Now, if you have a string, for example, if you have here string A, then also this reverse function
will work.
OK, so this inverse function is invoked C++ function.
So finally the time and the space complexity time is linear and we are using constant extra space.
OK.
So if you have any doubt in this problem, please ask.
OK, thank you.