You are viewing a single comment's thread. Return to all comments →
C++ code solution
vector<int> largestPermutation(int k, vector<int> arr) { vector<int> cparr; cparr = arr; sort(cparr.rbegin(), cparr.rend()); long count = 0; for (long i = 0; i < cparr.size(); i++){ if (count == k){break;} for (long j = i; j < arr.size(); j++){ if (arr[j] == cparr[i] && i != j){ swap(arr[i],arr[j]);count++; break; } } } return arr; }
Seems like cookies are disabled on this browser, please enable them to open this website
Largest Permutation
You are viewing a single comment's thread. Return to all comments →
C++ code solution