method returns true if string contains valid parenthesis
function isValidString ( str ) { let cnt = 0 ; for ( let i = 0 ; i < str . length ; i ++ ) { if ( str [ i ] == ' ' ) cnt ++ ; else if ( str [ i ] == ' ' ) cnt -- ; if ( cnt < 0 ) return false ; } return ( cnt == 0 ) ; }