Check if both halves of the string have at least one different character | Javascript implementation of the problem ; Function which break string into two halves Increments frequency of characters for first half Decrements frequency of characters for second half true if any index has non - zero value ; Declaration and initialization of counter array ; Driver function
let MAX = 26 ; function Function ( str ) { let l = str . length ; let counter = new Array ( MAX ) ; for ( let i = 0 ; i < MAX ; i ++ ) counter [ i ] = 0 ; for ( let i = 0 ; i < l / 2 ; i ++ ) counter [ str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; for ( let i = Math . floor ( l / 2 ) ; i < l ; i ++ ) counter [ str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] -- ; for ( let i = 0 ; i < MAX ; i ++ ) if ( counter [ i ] != 0 ) return true ; return false ; } let str = " " ; if ( Function ( str ) ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ;