Please tell the error

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ll n,k,hold,temp;
cin>>n>>k;
ll arr[n];
unordered_map<int,int>map;
for(ll i=0;i<n;i++)
{
cin>>arr[i];
map.insert(make_pair(arr[i],i));
}
ll m=0;
while(m<n && k>0)
{
hold=map[n-m];
if(hold==m)
{
m++;
continue;
}
else
{
temp=arr[m];
arr[m]=arr[hold];
arr[hold]=temp;
map.insert(arr[hold],hold);
map.insert(arr[m],m);
m++;
k–;
}
}
for(auto x:arr)
cout<<x<<" ";

return 0;

}

@ayushijaan23 Please save your code on ide.codingblocks.com and then share its link.

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.