Check if a string can be emptied by removing all subsequences of the form "10" | Function to find if string is reducible to NULL ; Length of string ; Stack to store all 1 s ; Iterate over the characters of the string ; If current character is 1 ; Push it into the stack ; Pop from the stack ; If the stack is empty ; Driver code
function isReducible ( str ) { let N = str . length ; let s = [ ] ; for ( let i = 0 ; i < N ; i ++ ) { if ( str [ i ] == ' ' ) s . push ( str [ i ] ) ; else if ( s . length > 0 ) s . pop ( ) ; else return false ; } if ( s . length == 0 ) { return true ; } else { return false ; } } let str = " " ; if ( isReducible ( str ) ) document . write ( " " ) ; else document . write ( " " ) ;