Check if both halves of the string have at least one different character | JavaScript program implementation of the problem ; Function which break string into two halves Counts frequency of characters in each half Compares the two counter array and returns true if these counter arrays differ ; Declaration and initialization of counter array ; Driver code
let MAX = 26 ; function functions ( str ) { let l = str . length ; let counter1 = [ ] ; let counter2 = [ ] ; for ( let i = 0 ; i < MAX ; i ++ ) { counter1 [ i ] = 0 ; counter2 [ i ] = 0 ; } for ( let i = 0 ; i < l / 2 ; i ++ ) counter1 [ str [ i ] - ' ' ] ++ ; for ( let i = l / 2 ; i < l ; i ++ ) counter2 [ str [ i ] - ' ' ] ++ ; for ( let i = 0 ; i < MAX ; i ++ ) { if ( counter2 [ i ] != counter1 [ i ] ) return true ; } return false ; } let str = " " ; if ( functions ( str ) != 1 ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ;