Hi, everyone.
So in this video, we are going to solve this question find by Magnetation.
OK, so basically the caution statement is very long, so since the statement is very long, we will
read the question on the website only.
OK, so in order to open the website, so basically this question, find permutation, this is present
in private and this is also present unlettered.
OK, but the problem.
But the problem with the law today is basically the problem with this question is basically, if you
will open the question so you can only open the question when you have premium subscription, OK, otherwise
you cannot open the question.
OK.
They have only provided you the solution.
So if you want to with the solution, they have provided three solutions.
OK, using the hashtag using reversing the SABERA and the two pointer approach.
So if you want to read the question, you can read it to herself.
OK, we will solve this questionnaire in private, OK, because in the literature we need premium subscription
to submit our answer and we don't have it.
OK, so now let us solve the discussion and debate.
So let us read the problem statement.
So but the statement is quite simple.
So what we have to do, so the input will basically be a string and the string will only content to
let us later or later.
OK, and we have a positive integer and as input.
OK, so if you have two things as input string and a positive integer and contain only two letters,
string will contain only two letters.
Durai.
OK, and what do you have to do?
So we have to find any permutations of the first and positive integer.
So that means I can only use basically one, two, three, four up to end.
OK, we can only use this numbers.
We can only use these numbers to find our reputation to generate our one rotation.
We cannot use and plus one we cannot use.
And plus two.
OK, so these are wrong.
We have to use this number.
OK, how many numbers are there, so there are total numbers, so I have to generate a permutation so
the size of the bottom rotation will be in OK, and what is the condition?
So condition is basically.
So if the character is dead, the next number will be smaller.
So if the characters die, the next number will be smaller.
If the character is basically a if the character is a, that means the next number will be greater.
OK, so this is the condition for generating this permutation.
OK, let us take an example to understand the question.
OK, now the value of this basically three.
So that means I can use three numbers one, two and three.
OK, and this thing is basically 80.
So the string is basically 80.
So what is the meaning of so I the next number should be greater?
OK, this is the output.
So the output is basically one, three and two.
So the meaning of AI is basically the next number should be greater.
OK, so C1 three is good than when it is following this condition.
OK, now the next character is the.
So the next number should be smaller.
So two is basically smaller than three.
OK, the list basically smaller than three.
So that's why this is the output.
OK, this is the output.
This is my permutation.
OK, this is my permutation, very, very simple.
So what we have to do, so basically the size of our reputation will be an OK size.
Our reputation will be and is the given integer.
We have to use each and every number.
OK, I will use all the numbers starting from one to Dilan.
Because I have to follow this condition next, unsimilar no condition, OK, and the stingray's is basically
and minus one.
OK, so if they atay.
If I were on is basically of Sastry then the string is basically of size two.
OK, let us take one more example.
OK, now remember this thing and now we are taking example's or Dimmeys.
Next time we should be smaller.
I mean snick some should be greater.
OK.
So if the character is Dean Distin, the next number should be the next number should be smaller and
for the next number should be greater.
OK, now suppose if the string is basically I and and we will always be three, OK, and we will be
one more plus one.
OK, so the answer will be basically one, two and three.
OK, so the meaning of is basically next number should be greater, so two is greater than one.
Similarly, for a basically three is greater than two.
OK, so this is the right permutation.
OK, take one more example.
So the value of this letter did and and is basically three, OK, obviously twilly plus one.
Now, the answer will be basically two to one.
So Damian's next number should be smaller, so considerately so please, basically smaller malignantly,
similarly, one is basically smaller than two.
OK, next number should be smaller.
Now, let us take one more example, so the value of land is basically safe and lasting, let's say
it is the I did.
OK, so my output will be Fischman 42.
OK, so Demi's next number should be smaller, so one is smaller than five, correct?
Amy's next number should be greater.
So basically, Ford is greater than one correct answer.
B should be next number should be smaller.
So threes smaller than four, correct answer.
Next number should be smaller.
So two is basically smaller than three.
So correct answer.
OK, and it's five means I have to use all the numbers starting from one till five.
OK, I have to use all the numbers.
So in total I have to use five numbers.
That's why the size of the ad is basically five.
Similarly, I have to use three numbers.
One, two, three.
That's why the size of that is three.
I have to use three numbers.
That's why the size of the ad is basically three.
OK, so I hope by now you have understood the question.
OK, so the input will basically be a string, a number and the string will contain only two characters,
DNA testing.
We can only these two type of characters.
The next number should be smaller in Japan rotation and I mean the next number should be greater.
OK, and these are some examples.
Now let us discuss how we control discussion.
OK, so basically what is the meaning of a.
So what is the meaning of a suicide note, the next number should be larger.
OK, so what we will do, we will put the smallest element.
OK, so what I'm trying to say.
So this is my said.
This is my third, it is containing one, two, three elements, I have to use each and every element.
OK, I have to use each and every element.
So the meaning of eye is basically the next number should be the next number should be larger.
OK, so what I am trying to say here is whenever you see a whenever we will see what we will do.
So basically we will substitute the smallest remaining number from the set, OK, corresponding to the
eye, OK, as it automatically makes the next element to be larger.
I am repeating myself.
So whenever you will encounter I, our aim is basically to make the next number greater.
So what we will do, we will put the smallest element, we will select the smallest element and we will
put it in the place of a small take smallest element and put it in place of a.
Similarly, whenever you have basically been so diminished, the next number should be smaller.
So what I will do, I will select the largest element, I will select the largest element, and I will
put it in the place of the.
Now, let's take an example, so this example only.
OK, so our logic is very simple, so if you are encountering the that means put the largest element,
put not largest element.
If you encounter I, that means put.
The smallest element.
If I will put the smallest element, the next element will always be a larger element.
If I put the largest element, then the next element will always be the smaller element.
OK.
I'm repeating myself, this is basically the main idea is the main idea, if you encountered where do
we look, we will put the largest element.
From our side, so that will automatically make the next number smaller.
OK, if I will put the largest element from the side, then it automatically means the next number will
be smaller, so our condition is met.
Similarly, if I encounter, I will put the smallest element.
So the next element will always be the larger element.
You can see yourself.
Whenever you encounter, the next element should be smaller.
OK, next element should be smaller.
So for making the next element smaller, I will put the largest element here.
Similarly, if I encountered what I will do, I have to make the next element larger.
So for making the next element larger, I will put the smallest element simple.
Now let's take an example so we can understand.
OK, so let us take this example, DADT and our answer is five.
One, four, three, two.
OK.
So basically estranges be a the the what are our elemental our elements are one, two, three, four
and five.
OK.
Now, it look, we will take two point us, so let's call it basically start, let's call it and.
OK.
Now, our logic is so our logic was Dimmeys put.
Largest element, because I have to make this next element smaller and I put the smallest element.
OK, this is a I mean, the smallest element.
So this was the condition.
This means I have to make the next number smaller.
It means I have to make the next to no greater.
So for making this condition, I have to do this.
OK, so demons, pathologist, largest armies, but smallest.
So be what is the meaning of the fourth largest logistics, basically five, OK, so this is basically
sorted.
This is sorted.
So put five.
I mean, sportsmen.
So when is the smallest, so after putting five, but I will do, I will do and minus minus.
Now I miss, but smallest, so smallest is basically the start, so I will put one and I will do start
placeless.
The spotlight, just so this is the largest support, largest land mine, this mine, this.
Again, the diminished but largest, OK, but largest, so I will put three and I will do any minus
minus support three and finally I will become.
But there is one element in our side, so I will write to also.
OK, so this is my answer.
Five, four, five.
One, four, three, two.
OK, five, 142.
And you can see our answer is correct.
Five, one, four, three, two.
OK, let's take some more examples.
Just remember this condition and now let us take somewhat example, remember this condition, so this
is basically let's call it idee, OK, so the value of N will be three.
So this is one.
This is two.
And this is three.
This is my start.
This is my end.
OK, so I means put smallest.
So put one.
But start a head start, plus the spotlight, just logistics to support three and two and a minus minus.
And finally, I will end and we have one character left, so I will do so for this input variety.
This is my answer.
One, three, two.
OK, let's take one more example, this thing is basically I'm OK, and I have one, two, three.
So I mean, sports analyst, so I mean, sports analyst, when this smallest again, I mean sportsman
is to report to and thing will end.
So I the remaining element is this.
So I will put this is my answer.
Let's take one more example.
ESPN's duty.
OK, and my this is my favorite part of this is start.
This is end.
So be me sport.
Largest city's largest redeeming sport, largest city's largest, Portree, again, the largest BU's
largest, because I will do end minus minus supporta, then I will do N minus MINURSO and will come
here and finally this thing will end.
I have one element left, so I will right that one element.
So this is my answer.
Two to one.
OK, understood.
I'm repeating myself, what is the logic?
So this is the question.
Demeans the next element should be smaller.
And what I'm saying here is if you encounter the largest element because it will put the largest element,
the next element will automatically be smaller.
Similarly, I miss the next element should be greater.
And here I'm saying I support the smallest element because it will put the smallest element.
Then the next element will always be greater.
OK, simple.
So this is to point that approach.
I will take 2.5 start points and end point that, OK, now let's write the code.
So we will ride the coat on in private.
OK?
I already told you we would like to go it because this question is not present only to.
So in order to write the code.
So basically, we have to return the property.
Yes, OK, we do not have to print something.
We have to return Retrophin pages and put basically string and a number and.
OK, so since we have to return the property, just let us make a vector of integers, OK?
Let's call it answer.
So it will be an OK it says will be in no time to do.
I have to take two point start point at any point as a start point there will be one.
And there will be in OK.
And if the largest element now we have to do I have to get rid of this thing.
OK, so now let us rid of the strings.
So Y equals zero I and astrocyte.
No simple conditions or if I will encounter.
So if the given character is the.
So if the government exposed what I have to do.
So I have to put the largest element that means end point.
OK, so what I will do instead of a.
So this is basically end.
OK, I have to put the largest element, then I will do.
And my niece.
My niece.
In the Elzbieta you can write, I will start.
So I will start I will start placeless, simple, finally after what I have to do.
So one element will be left, OK, you can see carefully there's always one element left.
There's always one element left.
The last one element, OK, so the last element will be left.
So instead of lasting Nix's and minus one, OK, you can write start or you can also write and they
both are saying, OK, you can write a starter and they both are the same.
Finally, our answer is so we can return our answer.
OK, simple.
This is the computer knowledge testable code and then we will submit.
OK, so there's some mistake here.
OK, so the mistake is basically the name of the string is S and I'm creating S here also.
So let's make it start.
OK, so what I will do.
I will ride here and similarly, this is a start, plus, plus.
This is basically start OK now I think it'll work fine.
OK, let's test.
OK, so I forgot to add semicolon.
OK, so semicolon, some completion error.
OK, so now let's summered.
OK, so our goal is working fine.
OK, now let's discuss the time and the space complexity.
So basically the time complexity is big often, OK, what we are doing, we are using to point that
approach.
I have a start point there and similarly, I have an end point there.
OK, so we are just getting on with the string and the string sizes basically and minus one, OK, this
size is basically and minus one to the time.
Complexity is big often and the space complexities big of one.
OK.
The code is very simple, if you will encounter the word doing, but the largest element.
Because if it will put the largest element, the next element will always be the smaller element, which
is the requirement.
Similarly, if you will encounter a you will put the smallest element because it will put the smallest
element that will automatically makes the next element a larger element.
And that is the requirement.
OK, so requirement is fulfilled.
Finally, we can take an example and we can understand there is always one element left which is not
pushed inside the answer vector.
This is the director and the last index is basically and minus one.
So you can write start or you can also write and hear.
OK, and then I'm returning my answer.
OK, so this question was basically asked in the Google telephonic interview.
OK.
So when I gave the interview for Google, they asked me this question in their telephonic round.
OK, so if you have any doubt in this question, you can ask me.
OK, thank you.