Can not solve the problem

#include
#include
#include <unordered_map>

using namespace std;

int main() {
int n,k,arr[100000],i,hold;
cin>>n>>k;
unordered_map<int,int> m1;

for(i=0;i<n;i++){
    cin>>arr[i];
    m1.insert(make_pair(arr[i],i));
    
}

int num=n;
    int m=0;
    while(m<n && k>0) {
    	
        auto f= m1.find(num-m);
        
		if(f!=m1.end()){
         hold=f->second;
        if(hold==n-num+m) { // Check if the number is present at the best spot
            m++;
            continue;
        } else { // If the number is not present at the best spot then swap the number with the element at that spot 
            swap(arr[hold],arr[m]);
            m1.insert(make_pair(arr[hold], hold));
            m1.insert(make_pair(arr[m],m));
            m++;
            k--;
        
    }}}
    for (auto i = m1.begin(); i != m1.end(); i++) 
    cout << i->first << "  "; 
          

    return 0;
}

this is my answer in c++ .please guide me to right answer

where’s the question???

Hey your map values are not getting updated. dont use insert after swapping use this.

    swap(arr[hold],arr[m]);
    m1[arr[hold]] = hold;
    m1[arr[m]] = m;

and also dont print m1->first after the commpletion of while loop. This is an unordered map. It doesn’t store values in any order and also using ordered map wil not help as it stores the keys in the sorted order.
You need to print the array after the while loop.

    for(int i = 0; i < n; i++)
        cout << arr[i] << " ";

You can check this.

can u please share the question?

The question name is “Unlock”. You can find it in your course.

https://hack.codingblocks.com/app/contests/916/p/1556

Here it is. Found it.