Smallest positive number made up of non | Function to find smallest positive number made up of non - repeating digits whose sum of its digits is equal to n ; No such number exists ; Stores the required answer ; Store the digit at unit 's place ; Iterate until n > digit ; Push digit at the start of res ; Decrement n by digit ; Decrement digit by 1 ; Push the remaining number as the starting digit ; Print the required number ; Driver Code ; Function Call
function result ( n ) { if ( n > 45 ) { document . write ( - 1 ) ; } var res = " " ; var digit = 9 ; while ( n > digit ) { res = String . fromCharCode ( 48 + digit ) + res ; n -= digit ; digit -= 1 ; } if ( n > 0 ) { res = String . fromCharCode ( 48 + n ) + res ; } document . write ( res ) ; } var N = 19 ; result ( N ) ;