Largest Permutation Discussions | Algorithms | HackerRank
We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
def largestPermutation(k, arr):
# Write your code here
arr_sorted=sorted(arr,reverse=True)
if k>=len(arr): return arr_sorted
arr1=arr
for i in range(k):
arr_en=[[q,p] for p,q in enumerate(arr1)]
arr_en=sorted(arr_en,reverse=True)
print(arr_en)
x=arr_en[i][0]
indx=arr_en[i][1]
arr1[i],arr1[indx]=x,arr1[i]
return arr1
whats wrong with my code
Cookie support is required to access HackerRank
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 →
def largestPermutation(k, arr): # Write your code here