For future me Bisth ji


#1

vector Solution::solve(vector &A, int B) {
unordered_map<int,int> m;
for(int i=0;i<A.size();i++)
m[A[i]] = i;
for(int i=0;i<A.size()&&B;i++){
if(A[i]!=A.size()-i){
B–;
//cout<<A[i]<<" "<<A[m[A.size()-i]]<<endl;
int x = A[i];
swap(A[i],A[m[A.size()-i]]);
int y = m[A.size()-i];
m[A.size()-i] = i;
m[x] = y;
}
}
return A;
}