Ques:-https://www.hackerrank.com/challenges/largest-permutation/problem
Ans:-vector largestPermutation(int k, vector arr) {
int i=0;
int n=arr.size();
while(k–){
int max=*max_element(arr.begin()+i,arr.end());
auto it=find(arr.begin()+i,arr.end(),max);
swap(arr[i],arr[it-arr.begin()]);
i++;
}
return arr;
}
Please tell me where my logic is wrong