Test Case :
1
5
1 4 3 2 5
Output :
1 2 4 3 5
While Your code gives 1 2 3 4 5.
you need to make sure if you swap i with i+1 then that i can’t be used again.
in addition to using each unique operation atmost once, you also need to check if the number on the left is greater than the number being considered, if not then don’t swap and break.
since we want smallest possiboe array and we can perform one kind of oepration only once i find out the min element and bring it to its position now see all moves before its real pos has been used so i updated s likewise
I was also stuck trying to think about this Problem.Can you explain me what is lexicographically minimum Possible combination. and To approach for this Problem.
Logic to solve B
Intuition was easy but implementation was difficult.
Now we need to check in every pass minimum value in between a particular set of indices i to n and place it at front at i and shift each value one step beyond… for example we have 5 4 1 3 2 now when we traversed for first time we got minimum value as 1 and at index 2 so we swap indices 2 and 1 then indices 1 and 0 to get 1 in front then in another pass we will start from indices 2 to indices n and then find the minimum again as at index 4 then we will swap indices 4 and 3 then indices 3 and 2 to get the final array 1 5 2 4 3 to satisfy the condition that no two indices can be swapped again.