text: Form minimum number from given sequence | C # program to print minimum number that can be formed from a given sequence of Is and Ds ; Prints the minimum number that can be formed from input sequence of I ' s ▁ and ▁ D ' s ; Initialize current_max ( to make sure that we don 't use repeated character ; Initialize last_entry ( Keeps track for last printed digit ) ; Iterate over input array ; Initialize ' noOfNextD ' to get count of next D 's available ; If letter is ' I ' Calculate number of next consecutive D 's  available ; If ' I ' is first letter , print incremented sequence from 1 ; Set max digit reached ; If not first letter Get next digit to print ; Print digit for I ; For all next consecutive ' D ' print decremented sequence ; If letter is ' D ' ; If ' D ' is first letter in sequence Find number of Next D 's available ; Calculate first digit to print based on number of consecutive D 's ; Print twice for the first time ; Store last entry ; If current ' D ' is not first letter Decrement last_entry ; Driver code
code: using System ; class GFG { static void PrintMinNumberForPattern ( String arr ) { int curr_max = 0 ; int last_entry = 0 ; int j ; for ( int i = 0 ; i < arr . Length ; i ++ ) { int noOfNextD = 0 ; switch ( arr [ i ] ) { case ' I ' : j = i + 1 ; while ( j < arr . Length && arr [ j ] == ' D ' ) { noOfNextD ++ ; j ++ ; } if ( i == 0 ) { curr_max = noOfNextD + 2 ; Console . Write ( " ▁ " + ++ last_entry ) ; Console . Write ( " ▁ " + curr_max ) ; last_entry = curr_max ; } else { curr_max = curr_max + noOfNextD + 1 ; last_entry = curr_max ; Console . Write ( " ▁ " + last_entry ) ; } for ( int k = 0 ; k < noOfNextD ; k ++ ) { Console . Write ( " ▁ " + -- last_entry ) ; i ++ ; } break ; case ' D ' : if ( i == 0 ) { j = i + 1 ; while ( j < arr . Length && arr [ j ] == ' D ' ) { noOfNextD ++ ; j ++ ; } curr_max = noOfNextD + 2 ; Console . Write ( " ▁ " + curr_max + " ▁ " + ( curr_max - 1 ) ) ; last_entry = curr_max - 1 ; } else { Console . Write ( " ▁ " + ( last_entry - 1 ) ) ; last_entry -- ; } break ; } } Console . WriteLine ( ) ; } public static void Main ( String [ ] args ) { PrintMinNumberForPattern ( " IDID " ) ; PrintMinNumberForPattern ( " I " ) ; PrintMinNumberForPattern ( " DD " ) ; PrintMinNumberForPattern ( " II " ) ; PrintMinNumberForPattern ( " DIDI " ) ; PrintMinNumberForPattern ( " IIDDD " ) ; PrintMinNumberForPattern ( " DDIDDIID " ) ; } }