Check if a string can be made empty by repeatedly removing given subsequence | Function to check if a string can be made empty by removing all subsequences of the form " GFG " or not ; Driver Code
function findIfPossible ( N , str ) { let countG = 0 , countF = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( str [ i ] == ' ' ) countG ++ ; else countF ++ ; } if ( 2 * countF != countG ) { document . write ( " " ) ; } else { let id = 0 ; let flag = true ; for ( let i = 0 ; i < N ; i ++ ) { if ( str [ i ] == ' ' ) { countG -- ; id ++ ; } else { countF -- ; id -- ; } if ( id < 0 ) { flag = false ; break ; } if ( countG < countF ) { flag = false ; break ; } } if ( flag ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } } let n = 6 ; let str = " " ; findIfPossible ( n , str ) ;