Minimum possible number with the given operation | C # implementation of the above approach ; Function to return the minimum possible integer that can be obtained from the given integer after performing the given operations ; For every digit ; Digits less than 5 need not to be changed as changing them will lead to a larger number ; The resulting integer cannot have leading zero ; Driver code
using System ; class GFG { static string minInt ( char [ ] str ) { for ( int i = 0 ; i < str . Length ; i ++ ) { if ( ( int ) str [ i ] >= ( int ) ( '5' ) ) { str [ i ] = ( char ) ( ( ( int ) ( '9' ) - ( int ) ( str [ i ] ) ) + ( int ) ( '0' ) ) ; } } if ( str [ 0 ] == '0' ) str [ 0 ] = '9' ; string s = new string ( str ) ; return s ; } static public void Main ( ) { string str = "589" ; Console . WriteLine ( minInt ( str . ToCharArray ( ) ) ) ; } }