Lexicographically smallest permutation of size A having B integers exceeding all preceding integers | C # program for the above approach ; Function to find lexicographically smallest permutation of [ 1 , A ] having B integers greater than all the previous elements ; Initial array ; Resultant array ; Append the first ( B - 1 ) elements to the resultant array ; Append the maximum from the initial array ; Copy the remaining elements ; Print the answer ; Driver Code
using System . Collections . Generic ; using System ; class GFG { static void getSmallestArray ( int A , int B ) { List < int > arr = new List < int > ( ) ; for ( int i = 0 ; i < A ; i ++ ) arr . Add ( i + 1 ) ; List < int > ans = new List < int > ( ) ; for ( int i = 0 ; i < B - 1 ; i ++ ) ans . Add ( arr [ i ] ) ; ans . Add ( arr [ A - 1 ] ) ; for ( int i = B ; i < A ; i ++ ) ans . Add ( arr [ i - 1 ] ) ; for ( int i = 0 ; i < A ; i ++ ) Console . Write ( ans [ i ] + " ▁ " ) ; } public static void Main ( ) { int A = 3 ; int B = 2 ; getSmallestArray ( A , B ) ; } }