Lexicographically smallest permutation of first N natural numbers having K perfect indices | Function to prvar the lexicographically smallest permutation with K perfect indices ; Iterator to traverse the array ; Traverse first K array indices ; Traverse remaining indices ; Driver Code
function findPerfectIndex ( N , K ) { var i = 0 ; for ( ; i < K ; i ++ ) { document . write ( ( N - K + 1 ) + i + " " ) ; } for ( ; i < N ; i ++ ) { document . write ( i - K + 1 + " " ) ; } } var N = 10 , K = 3 ; findPerfectIndex ( N , K ) ;