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;
}