TLE Error in the code

My code is passing all the testcases except the last one which is giving TLE.
Below is my Code :

#include<bits/stdc++.h>
using namespace std;

int main()
{
int N,k;
cin>>N>>k;
int arr[N];
for (int i = 0; i < N; i++)
{
cin>>arr[i];
}
int i=0;
int count = 0;
int n=N;
if(k==0)
{
for (int i = 0; i < N; i++)
{
cout<<arr[i]<<" “;
}
}
else
{
while(i<N && count<k)
{
if(arr[i]!=n)
{
int index = find(arr,arr+N,n)-arr;
swap(arr[index],arr[i]);
count++;
}
n–;
i++;
}
for (int i = 0; i < N; i++)
{
cout<<arr[i]<<” ";
}
}

return 0;

}

@vritant2405 your solution is using the find fucntion and in the worst case your programe can work in o(n2) which will cause tle for findind the index which you are doing throuh find function use a map to store inices and then get the index of any element in o(1) and rest is the same you are following
Coding Blocks IDE
this is the code if you still have any issue feel free to ask and if clear please mark it as resolved and rate my experience

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.

I got my mistake. Thank you for correcting me.