Check if a string can be rearranged to form special palindrome | driver code ; creating a array which stores the frequency of each character ; Checking if a character is uppercase or not ; Increasing by 1 if uppercase ; Decreasing by 1 if lower case ; Storing the sum of positive numbers in the frequency array ; Storing the sum of negative numbers in the frequency array ; If all character balances out then its Yes ; If there is only 1 character which does not balances then also it is Yes
let s = " " ; let u = Array ( 26 ) . fill ( 0 ) ; let n = s . length ; for ( let i = 0 ; i < n ; i ++ ) { if ( s [ i ] . toUpperCase ( ) ) { u [ s [ i ] - 65 ] += 1 ; } else { u [ s [ i ] - 97 ] -= 1 ; } } let f1 = true ; let po = 0 ; let ne = 0 ; for ( let i = 0 ; i < 26 ; i ++ ) { if ( u [ i ] > 0 ) po += u [ i ] ; if ( u [ i ] < 0 ) ne += u [ i ] ; } if ( po == 0 && ne == 0 ) document . write ( " " ) ; else if ( po == 1 && ne == 0 ) document . write ( " " ) ; else if ( po == 0 && ne == - 1 ) document . write ( " " ) ; else document . write ( " " ) ;