here is the link for my code https://ide.codingblocks.com/s/65273 i was writing solution code for problem unlock. link for the problem is https://online.codingblocks.com/player/15208/content/5364
Getting runtime error please tell why and how to solve that
Hi
please refer to this code, you can see the changes
#include
#include
using namespace std;
int main(){
int n,i;
cin>>n>>i;
int arr[n],arr2[n+1];
for(int j=0;j<n;j++)
cin>>arr[j];
for(int j=0;j<n;j++){ /// changes made here
arr2[arr[j]]=j;
}
for(int j=0;j<n;j++){
///cout<<arr[0]<<" "<<j<<"\n";
if(i==0)
break;
if(arr[j]==n-j)
continue;
else{
int temp=arr2[n-j];
swap(arr[temp],arr[j]);
arr2[arr[temp]]=temp;
i--;
}
}
for(int j=0;j<n;j++)
cout<<arr[j]<<" ";
}