Sort given array to descending | Function to sort first K array elements in descending and last N - K in ascending order ; Sort the array in descending order ; Sort last ( N - K ) array elements in ascending order ; Driver Code
def sortArrayInDescAsc ( arr , N , K ) : NEW_LINE INDENT arr = sorted ( arr ) NEW_LINE arr = arr [ : : - 1 ] NEW_LINE for i in arr [ : K ] : NEW_LINE INDENT print ( i , end = " ▁ " ) NEW_LINE DEDENT for i in reversed ( arr [ K : ] ) : NEW_LINE INDENT print ( i , end = " ▁ " ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 7 , 6 , 8 , 9 , 0 , 1 , 2 , 2 , 1 , 8 , 9 , 6 , 7 ] NEW_LINE N = len ( arr ) NEW_LINE K = 6 NEW_LINE sortArrayInDescAsc ( arr , N , K ) NEW_LINE DEDENT