Largest Permutation Discussions | Algorithms | HackerRank

Largest Permutation

  • + 0 comments

    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