➤ Problem Link : 1256B. Minimize the Permutation
✅ C++ Solution :
#include<bits/stdc++.h>
using namespace std;
int main()
{
int q;
cin>>q;
while(q--)
{
int n;
cin>>n;
int arr[n] ;
for(int i=0;i<n;i++)
cin>>arr[i];
int i=0;
while(i<n)
{
int mn=i;
for(int j=i+1;j<n;j++)
{
if(arr[j]<arr[mn])
mn=j;
}
for(int j=mn;j>i;j--)
{
int temp=arr[j];
arr[j]=arr[j-1];
arr[j-1]=temp;
}
if(mn==i)
i++;
else
i=mn;
}
for(int i=0;i<n;i++)
cout<<arr[i]<<" ";
cout<<"\n";
}
}
Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook.
😇Happy Learning!!
