Hi, everyone.
So today we are solving this problem, remove all ideas and duplicates, part two.
OK, so what is the difference in this problem?
So the difference is basically you will be given the valley of.
So in the only problem, the last one that we have solved.
So we have to remove two adjacent equal letters.
OK, so we have to remove to a different equalitarian the last problem.
But here the value of two, for example, here the value of K will be given.
OK, so we have to remove duplicates.
We can see.
So this problem is also present on the code.
So what we have to do here, so basically we have to remove duplicate.
OK.
And again, we will do it repeatedly.
OK, so we will choose a decent and equal letters and then we will remove them.
OK, so he doesn't get a decent equal letters removal.
OK, so in the last problem that we have sold, the value of gave us two.
OK, so in the previous column, the value of K was to retain the value of K will be given by the user.
OK, so let's see, let's see some examples first.
So this is important basically and string and this is the value of K, so there are no two additional
characters, so the output will be absolutely only OK.
So there is nothing to remove here the value of case three.
So I will remove these three.
I will remove these three.
So virtually my string, so my string will become the then the then B, B, B, D, E, and so again,
as you can see here.
So we have this B, B, B, so we will remove it then.
What will be our string suggesting will become D, D the A A now again we can see here.
So this is again.
We will remove these trees so our strength will become A&E.
OK, so this will be our output.
OK, so now let us consider this example.
So the value of KS to OK, so I will remove these two.
I will remove these two.
Then I will remove these two.
Then these two.
OK, so this hole will be removed.
So what will be our strength?
So this will be then we shall see.
So B.C. then again, we shall see.
Then we have I.
And then again, we have and so I and it's OK.
So now what will happen to these two and these two?
They will be removed.
So my answer will be B and is OK, so this will be my output string.
This is are protesting now.
The problem is now the question is how can we solve this question?
OK, so in the previous question, the value of K was fixed, the value of K was to protect, the value
of K will be variable.
So how can we solve this question?
So we will use the same approach that we used in the earlier problem.
So basically we will take the help of Steck.
OK, we will take the help of technology, let's take an example and let's say we are taking this example.
So we will see how we can solve it with the help of a stick.
OK, so.
So I have the Tripoli deal, there will be see.
OK, so I have.
The Tripoli, they will be there, will see.
And then be so tripathy, be the policy b, b, e, e, and the Valley of Gays, basically three.
Let me again check.
So this the value of K Street.
OK, so we will take a strike now.
This time our strike will be different.
OK, so our strike will be a little different here.
So in the last problem, we created a stack of characters, but here our stack will contain two things.
OK, so the two things, I will make up it.
And inside the beer, it will store two things.
First is the character and secondly, the count of the character.
OK, so let's celebrate.
So we will trade over this drink.
So let's see.
So first, I am having correctly OK, so correctly we will push because this deck is empty.
So character count this one.
OK character and count so correctly.
Count one.
Now, so compare again, we are following the same approach.
OK, so we are following the same approach that we did in the last problem.
The only differences we are like we are maintaining a count variable also.
OK, so compare the current parliament with the top of the stack so evenly they are different.
So I will push it.
So push the count this one.
OK, now, so compare it with E!
OK, so they are saying, so what I will do, I will increase the count, so I will make the count to.
And then after making the count to I will check with the T. So the count is two and check the value
of street so I don't have to do anything.
OK.
Now, again, to compare it with me now, I will make the count three, so I will make this count three
now see the value of Kastari and our topmost element as count three.
So what I will do.
I will pop.
So we are following the same rules.
So the rules are very simple.
So rule number one, if the stack is empty.
So if.
Stack empty.
Then Bush.
So this was our Alirio also.
Now the second rule was so compare the current element.
So this is compare it to the current elements of the current element is not close to the top most element.
So basically stack up then.
Also, we are pushing the element.
Now, the third is so now the elements are equal.
Basically, this is the condition.
The current element is it goes to the topmost element of the stack.
Stacked on top, so stacked on top is going to things, so I want to compare the character, so I want
the character.
OK, so this is the coalition.
So if this is the coalition, would I have to do so?
I will do what I will do.
I will increase the count.
So increase the count.
So basically I can take count plus plus.
So we are increasing.
So this was one that I made it to and then I made it three.
OK, so we will do count plus plus.
And if the count becomes equal to the given value which is key then pop.
OK then Bob.
So this is the only difference here.
OK, so this is the significance of count.
If the count becomes key then pop now the so yes.
These present.
So what I will do.
I will.
So this is not here.
OK, so this is the topmost element of the stack right now to the custody.
So I will make the count to now compare the count two with three so they are not equal.
I will move ahead.
So be so I will push B so I am pushing B, so this is B and the count is one.
OK, then again B so I will make the count to.
Then see, so basically, see, this is see and the counties won again.
So make the count two again.
So make the count three.
As soon as the count becomes close to what I will do, I will pop.
OK, so I will pop now be to compare it to be at the top.
I am having the same element, so I will make the country.
So as soon as the count become close to me, I will pop.
So Bob, now currently my stack is only having one element, which is the and its count is to.
OK, so again B so what will you do.
So the current element is it goes to the topmost element to make the count three and three close together.
So I will pop the element.
Now my stomach is empty at this point.
OK, so I have e so my steak is empty so I have a small E and the count is one.
OK, again, so I have a and the current element is it goes to the topmost element, so I will increase
the count so and so basically this is my steak and then I will reach the end of the string.
So when I reach the end of the string this is my stack e and its count is to OK.
So how will I know my answer.
So basically this is my answer.
What I will do, I will pop the element.
So basically for constructing the answer, pop the element.
And it's this to so that since the count is two, I will write it two times and then our standard approach,
what will do?
We will reverse our answer.
So we will reverse.
So in this case, after reversing, we are getting the same answer and say, OK, but we have to reverse.
So I have to reverse.
OK.
Now, after everything in this case, we are getting the same answer, but the answer may have been
different.
OK, if you won't let us dry on one more example.
OK, so let us take one more example.
OK, so I'm taking example on my own, so let us say this is A, then B, then B and let's say I have
a A A again, I have led to B, then C, C, C, and then E, and let's say I have D here and then the.
OK, so let us consider this example.
OK, let us consider this one example.
And let's say the valley of caves, basically three.
OK, so let's see what will happen.
Let's put you here also.
OK?
And the value of K Street.
OK, so let us consider a stack.
Stack will contain two things counting character.
OK, so I will have a count.
I will have I will have character and its corresponding count.
OK.
So what I will do so I will create a stack of beer and beer is basically a glass which has two properties,
character and count.
OK, so let's see.
This is Dee.
So the count this one again, B, make the count to compare two with three.
They are different.
OK, so E.
So Bush counters once again, eh, so make the count to.
So I have been so push be counted as one again, be so we will make the count to.
Then push.
So I have the count is one again, a make the count to again, a make the count three.
OK, so at this point my count is three and three equals.
So what I'm going to do here is I will pop.
So Pop.
OK, so now let's move forward so I have B.
IFB, so what I will do, I will make the count three and three equals three equals K, so what I will
do, I will pop.
OK, so let's move forward, so I have see, so I have this see count is one again, C so count becomes
two again, C, so count becomes three.
And as soon as the count becomes equals to what I will do, I will pop.
OK, now let's move ahead.
So I have.
So this is a so I will make the count three and then I will pop.
Now that's more I have E so I have E count is one, then I have E, so count becomes two.
And then I will reach the end of the string.
OK, so what is my answer?
First, I will pop this element E and I will write two times E, so two times E, then I will pop this
element.
I will write two times the OK and then I will reverse.
So after reversing, my answer will be Dee Dee Dee, and so this is the correct answer.
OK, so you can also see from here, first of all, what will happen.
So I will remove these three and I will remove these three.
OK, so removing these three and removing these three.
So what will happen?
I will have B.
And this be.
Then it will be removed, then what will happen?
So I will have this to and this.
So then they will be removed and finally I will have died and this last two years.
So this will be our answer and our answer is basically right.
OK, so what will be our approach?
So first of all, I will make a stack of beer and what this beer is basically I think it will be a glass,
OK, and it's the type will be it will be collected in an integer.
So character basically let's call it first and integer, let's call it second.
OK, so character, you're going to distort the meaning of character and integer here.
So your second means basically the count.
OK, so I'm naming it first and second.
OK, so I hope you understand this question.
OK, so now let's write the code, ok.
So what I'm doing here is.
I am copping this cold.
I'll get admitted in the last session, so let us copy this could.
So what do we want, first of all, we need a glass, glass of beer.
For creating this tag.
OK, so I need to do the members first and second.
So, first of all, stole the character.
OK, so first we stole the character and second will store the count.
OK.
So this first.
This will store the character.
And the second.
It will store the count, OK?
It will store the count.
So what do I want?
So first of all, I want to create Aztek.
I will create a stack of beer.
OK, so let's say the name is is.
Then this is the old gold.
So, again, we have to ideato the eddy over the string, if the string is the stake is empty, I am
pushing and if they are different to the current element drop element, they are different then I'm
again pushing, but I have to push up it.
OK, so I have to push up bit.
So let us create a prayer first.
So I am creating an object of the class.
OK, so I am creating an object to BRP.
And I have to give its value, so the value, the character is of I and its count this one.
OK, so for this line to work, I have to create deconstruct.
But OK, so I have to create the constructor.
So let's create the constructor so I have this constructor beard.
It will take two things.
Character and count.
OK, so first and second, so first exclusive.
And technically, yes.
OK, so now I have a debate.
So after the debate, I am pushing peer inside the stack.
OK.
I am pushing the object to be.
OK, so now let us come to the part now in the last part, I cannot directly pop.
OK, so this is wrong.
I cannot pop.
So as we discussed what we are doing, so first we are increasing the count.
OK, so first, what we are doing, we are in the correct policy.
If the correct policy, we are increasing the count and then we are checking the count with the key.
OK, so first increase count and then check the count with key.
OK, so at this point, elements are saying, OK, so basically, Alphie, the current element is basically
close to the top element of the stick.
OK, so current element, top elements of what I have to do first, I have to increase the count of
the topmost element so as not top.
So after writing a start up, what will I get?
I will get a paper now to access the character.
To access the account.
I have to write second.
OK, so I start topknot.
Second.
Now, I would have to write placeless, so I've increased the count, so what is the count count as
basically a start?
Stop that second now.
What I have to do, I have to check the count.
So if the count.
Becomes close to what I have to do, I have to pop.
OK, so Astarte Pop.
So very simple.
OK, so now let us now hear what we are doing, so we are making our answer.
OK, so what we are doing while Steg is not empty.
So first of all, it will not be as top I as door top is basically what Azer Top is basically a pair.
It will return me a pair object and I want the character for character.
I have to write first.
OK, you can see here for playing the character, I have to write first.
So basically this is not right because as you can see here, as you can see here, so it was like D
and do so since it was two there.
And I have to write, I have to copy the two times, OK, I have to copy the two times so I have to
take care of count also.
So completely to times what I have to do.
So, first of all, we will find out the count.
OK, so how many times we need that character?
So for finding out the top, for finding out the count, we need the second and.
Well, count to minus minus.
How many times we need that element?
OK.
So after copping the element count times, I will pop that element and then I am reversing and then
I'm returning my answer, OK, so I hope everything is fine.
Now, let's try to run our record and then we will try to it.
OK, so.
OK, so this indexer, OK?
OK, so here we have to as dot dot basically is returning me.
Appear object, and I want the correct.
So for playing the character, I have to write first.
OK, so now let's run.
Now, let's try to sum it.
OK, so our court is working fine.
OK, so yes, our court is working fine.
Now, let's have a call one more time.
OK, so what we are doing here, so first of all, I am creating a stack of beer and what is beer?
Superior's containing two things.
So first one is restoring the character in the variable first, and it is the count in the variable
second.
OK.
So I'm creating a stack of beer.
The name is then I'm meditating over the string.
So if the steak is empty, then as discussed, we have to push up beer.
OK, so what staggers off beer.
So I have to push up here and start up.
So basically what is a up as there basically will return me a beer object.
It will return me a beer object.
Now I want to access the first element, I want to access its character.
OK, I want to kiss the characters, so I have to write that first.
OK, then here what I am creating.
I am calling the constructor.
OK.
So for calling the constructor, I need to pass two variables.
So I'm calling the constructor here and the character is basically of I and the count is basically one
and then I am pushing the character.
So in the ls part as discussed first, what we have to do, we have to do count plus plus we have to
increase the count.
So I am doing count plus also as the top is basically will return me the object and with the help of
dart second I will get the count.
So I'm doing that second plus plus.
So I'm starting the counting, the variable count and then I am checking this condition and the count
becomes key.
I am popping over element.
OK, and this is like the old code for getting the answer.
So while the stack is not empty, first of all, like we see in the previous examples of these appearing
two times.
So I have to copy these two times.
So that's why I will count minus minus.
So these many number of times, the first element will be copied.
And then after copying the element, we are popping the element, then reversing the element, reversing
the string, and then we are returning our answer.
OK, so wild card, minus minus.
So if you are getting confused, what is the meaning of wild card minus minus.
So it is basically like this.
Well count this guerdon zero.
Some work and then I'm going doing count minus minus.
OK, so this is short way too, right?
OK.
So this is short way to this thing.
Welcome, discordance zero, do this thing OK, so shortly.
Welcome to minus minus.
OK.
Now, one thing that I want to tell you here is so here what we are doing, so I'm creating a class.
Be it OK?
So I'm getting a glass where it has two properties, first and second.
So in this case it was in our case it was character first and can be just second.
OK, so in C++, we have a beer glass and we have inbuilt built class.
OK, we have built beer glass and the structure of inbuilt beer glass is very simple.
So it is glass beer.
Again, it will make public so it is like templated first.
And Bamblett.
Second, and it has all other functions that we will see in very short time, so template means basically
we can write in budget here, we can write character here, we can write flawed here, we can write
string here, OK, so we can write anything.
We can write that here, we can write map here, we can write Gule here.
We can write a stack here.
Basically we can write anything.
OK, so the inbuilt A which is already implemented in C++, that is very, very powerful.
OK, so we do not have to create the glass ourselves.
OK, so we have this in class and now we will now we will see how to use that better class.
OK, so for creating the steg.
What I will write, I will write back then, be it.
Then what I will do, so I need two things.
OK, so first and second and first will be character comma.
Second will be in danger because print count, so second will be integer.
So this is the syntax opening record and closing record for beer.
And now this is opening bracket and this is the closing bracket for beer.
And now the name of this deck, which is as so if you will write this now, it is wrong.
Why?
It is wrong because see.
Have you read this text before?
Yes, it is very similar to see in Goodin Goodin so the simplest reason to get confused here.
So what I have to do so I will write integer greater than this symbol.
So the symbolism of then I have to leave space, I will leave space, then I will right this second
one.
OK, so that C++ do not get confused between this operator, this radio operator.
OK, so I will leave a space.
OK, so.
Let's come out this part now, I will use and build a better class.
OK, so we are using and built better class.
We have a class in C++ and you should know how to use that class, so that's why I am covering that
topic here.
OK, so in class, let's see how to use it.
OK, so what I'm doing here, let's remove it from here.
Let's come out, everything OK?
Now, let's see in world class.
So it is very easy to use.
So let's first copy the code.
OK, so now we're creating a stick.
What I will write, I will write, I need a beer, which is already implemented in C++.
Now, the pair will have two things first and second.
So first, I want character.
Second, I want count.
OK, so and then I will leave a space and then this.
OK, so this is the syntax.
OK.
So you know why I would leave the space here?
Because.
Because you know it is like this only.
OK.
So I have to leave space so that C++ does not get confused again.
So I am I reading stack empty the top dog first.
So that first is already there in class.
OK.
It is first and second they are fixed you can see here.
So these names are fixed first and second, these names are fixed.
You cannot change these names.
OK, you only can decide that type.
OK, whether it will be integer character, flawed string vector map keywords stack or anything else
or priority.
Q OK, you cannot change the names.
The names are fixed of inbuilt class.
OK.
So the names are fixed, so we cannot change them.
So what I have to do, I have to push up here.
OK, so we're pushing up here.
So let us come and this part, OK, so let's delete this part.
So I have to push up here.
So we're pushing up here, but we have to do we have to make first so from making a beer, what can
do?
So I have a function.
Make beer.
So this is a function, make beer and I will give two things.
First, one should be character.
Second one should be in beta.
So first one should be collectivities of a second.
One should be in BIJA, which is one.
OK, very simple.
Now everything else will remain same.
OK, so yes.
Yes, everything else will remain, Tim.
Now, let's do another good.
See Sea of Cortez working.
And we do not have to implement any on our own.
OK?
We do not need to create Castlerock, but also so see, we are getting eight milliseconds.
Sow discord is faster.
OK, so we are not creating this because we do not need to write this code ourself.
OK.
So these variables and this construct, there is no need to write this, just simply use the inbuilt
berglas.
OK, so we have this in class.
You have to give two things first and second.
First one is correct.
The second one is of type integer, OK, for making the variable function, make beer and I'm giving
the first value should be character.
Second value should be integer.
OK, and everything else is seem.
So I think there is one more way to create a peer.
There is one more way to create a.
I I'm trying to remember the in so Burpee is basically I think if I.
Come on, I'm just trying it, I don't remember.
So Astarte, Bush.
B.
So let's see.
OK, so this is working OK, so we can also create a like this BRP and we can initialize in the same
line instead of using the McPaper function, we can write this one.
So if we can write this, I think we can also write like this.
Beilby.
So a.
Come on.
OK, so we can write like this also so we know there are three ways to make beer.
OK, so at this point we know there are three ways to make beer.
So the first rays.
BP is basically you give the values first value and the second value.
Now, the second option is basically BRP.
You give the first value, you give the second value, and the third option is basically using a make
beer function.
Make their first value, second value.
OK, so beer can be of any type, for example, you can create beer like beer of characters, khama
beer inside the beer.
So beer of, let's say, integer combine integer then FirstRand this bracket then I have to close this
bracket but A should be there.
OK as we should be there otherwise it will get so this will get confused.
So zipless will get confused with with this record this operator.
So USPI should be there.
And then the name for example to Putu.
OK, so Bill can be off anytime, so be of, let's see, first values, vector and vector of.
In Egypt now, the second value is basically, let's call it a map, so a map and inside the map, let's
see, I have I inside the map, I have beer and inside the beer, let's say I have Digicom integer.
So first the map will finish.
So this is map, then this one.
So this one.
And let's say this name is Peter.
OK, so in this way, like you can see, there is there are many uses of beer class.
OK, so beer glasses, very important.
So it is very important, it is like.
It is used heavily.
OK, so you should know how to be in class and inside the class, two variables are there.
There are only two variables first and second.
OK, so we have only two variables inside the beer glass.
So this is important.
We have only two variables.
OK, so they aim for solving this question was to introduce beer glass, and the second was to like
how to solve this question, OK?
So what is the time and the space complexity?
So basically the complexity of this question.
Is linear and space complexity, we are creating a strike.
So it is big often.
OK, so these are the time and the space complexity of this question.
OK, so we will be using Berglas whenever we can.
OK, so we will never create a class like this, OK?
There is no need to write class code for ourself, so this is basically a waste of time.
OK, so if you have any doubt in this question, you can ask me.
OK, thank you.