Function to check if a string contains equal number of one and zeros or not
function isValid ( p ) { var n = p . length ; var c1 = 0 , c0 = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( p [ i ] == ' ' ) c0 ++ ; if ( p [ i ] == ' ' ) c1 ++ ; } return ( c0 == c1 ) ? true : false ; }