Lexicographically smallest permutation of first N natural numbers having K perfect indices | Function to print the lexicographically smallest permutation with K perfect indices ; Iterator to traverse the array ; Traverse first K array indices ; Traverse remaining indices ; Driver Code
def findPerfectIndex ( N , K ) : NEW_LINE INDENT i = 0 NEW_LINE for i in range ( K ) : NEW_LINE INDENT print ( ( N - K + 1 ) + i , end = " ▁ " ) NEW_LINE DEDENT for i in range ( 3 , N ) : NEW_LINE INDENT print ( i - K + 1 , end = " ▁ " ) NEW_LINE DEDENT DEDENT N = 10 NEW_LINE K = 3 NEW_LINE findPerfectIndex ( N , K ) NEW_LINE