Form minimum number from given sequence | Function to decode the given sequence to construct minimum number without repeated digits ; result store output string ; create an empty stack of integers ; run n + 1 times where n is length of input sequence ; push number i + 1 into the stack ; if all characters of the input sequence are processed or current character is ' I ' ( increasing ) ; run till stack is empty ; remove top element from the stack and add it to solution ; main function
function PrintMinNumberForPattern ( seq ) { let result = " " ; let stk = [ ] ; for ( let i = 0 ; i <= seq . length ; i ++ ) { stk . push ( i + 1 ) ; if ( i == seq . length seq [ i ] == ' ' ) { while ( stk . length != 0 ) { result += ( stk [ stk . length - 1 ] ) . toString ( ) ; result += " " ; stk . pop ( ) ; } } } document . write ( result + " " ) ; } PrintMinNumberForPattern ( " " ) ; PrintMinNumberForPattern ( " " ) ; PrintMinNumberForPattern ( " " ) ; PrintMinNumberForPattern ( " " ) ; PrintMinNumberForPattern ( " " ) ; PrintMinNumberForPattern ( " " ) ; PrintMinNumberForPattern ( " " ) ;