Problem Link :- B. Minimize the Permutation
My Code :- My Code

Ive been struggling for 3 hours straight and I’m still not able to find the solution to and get an AC in the problem . You can get the question above .

Approach :
Just Applying the brute force , getting the smallest number , and putting in the leftmost position possible . and while putting it making sure that , the i -th operation is never performed while maintaining a check array .

Yes exactly I agree with you , I’m moving the smallest number to its optimal position which is when `index+1 == i` if we are able to achieve this , then we do this and if not , we move to the next number .
then to process `3` , before that `2` is processed , and since we are moving from smallest to biggest number therefore , the next number after `2` will either be on its leftmost position i.e. `num+1==i` or it will be not , therefore we will proceed only when `num+1!=i` , and if we proceed when `num+1==i` but we want the string to be lexo , the optimal place for number `i` should be its `num+1==i` .