Check if K palindromic strings can be formed from a given string | function to check whether the string is K palindrome or not ; map to frequency of character ; Check when k is given as same as length of string ; storing the frequency of every character in map ; if K is greater than size of string then return false ; check that number of character having the odd frequency ; if k is less than number of odd frequency character then it is again false other wise true ; Driver code
function can_Construct ( S , K ) { var m = new Map ( ) ; var i = 0 , j = 0 , p = 0 ; if ( S . length == K ) { return true ; } for ( i = 0 ; i < S . length ; i ++ ) { if ( m . has ( S [ i ] ) ) m . set ( S [ i ] , m . get ( S [ i ] ) + 1 ) else m . set ( S [ i ] , 1 ) } if ( K > S . length ) { return false ; } else { m . forEach ( ( value , key ) => { if ( value % 2 != 0 ) { p = p + 1 ; } } ) ; } if ( K < p ) { return false ; } return true ; } var S = " " ; var K = 4 ; if ( can_Construct ( S , K ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }