Rearrange characters of a string to make it a concatenation of palindromic substrings | Function to check if a string can be modified such that it can be split into palindromic substrings of length >= 2 ; Stores frequencies of characters ; Traverse the string ; Update frequency of each character ; Traverse the frequency array ; Update values of odd and eve ; Print the result ; Driver Code
function canSplit ( S ) { let frequency = new Array ( 26 ) . fill ( 0 ) let cnt_singles = 0 let k = 0 for ( let i = 0 ; i < S . length ; i ++ ) { frequency [ S . charCodeAt ( i ) - ' ' . charCodeAt ( 0 ) ] += 1 } let odd = 0 let eve = 0 for ( let i = 0 ; i < 26 ; i ++ ) { if ( frequency [ i ] ) { odd += ( frequency [ i ] & 1 ) } } if ( eve >= odd ) { document . write ( " " ) } else { document . write ( " " ) } } let S = " " canSplit ( S )