Lexicographically smallest permutation of first N natural numbers having K perfect indices | C ++ program for the above approach ; 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
#include <iostream> NEW_LINE using namespace std ; void findPerfectIndex ( int N , int K ) { int i = 0 ; for ( ; i < K ; i ++ ) { cout << ( N - K + 1 ) + i << " ▁ " ; } for ( ; i < N ; i ++ ) { cout << i - K + 1 << " ▁ " ; } } int main ( ) { int N = 10 , K = 3 ; findPerfectIndex ( N , K ) ; return 0 ; }