Largest string obtained in Dictionary order after deleting K characters | Function to find the largest string after deleting k characters ; Deque dq used to find the largest string in dictionary after deleting k characters ; Iterate till the length of the string ; Condition for popping characters from deque ; To store the resultant string ; To form resultant string ; Return the resultant string ; Driver code ; Given String ; Function call ; Print the answer
function largestString ( n , k , s ) { var deq = [ ] ; for ( var i = 0 ; i < n ; ++ i ) { while ( deq . length > 0 && deq [ deq . length - 1 ] < s [ i ] && k > 0 ) { deq . shift ( ) ; k -- ; } deq . push ( s [ i ] ) ; } var st = " " ; deq . forEach ( c => { st = st + c ; } ) ; return st ; } var n = 4 ; var k = 2 ; var sc = " " ; var result = largestString ( n , k , sc ) ; document . write ( result ) ;