Check if permutation of a given string can be made palindromic by removing at most K characters | Function to check if the string satisfies the given conditions or not ; Stores length of given string ; Stores frequency of each character of str ; Update frequency of current character ; Stores count of distinct character whose frequency is odd ; Traverse the cntFreq [ ] array . ; If frequency of character i is odd ; Update cntOddFreq ; If count of distinct character having odd frequency is <= K + 1 ; Driver Code ; If str satisfy the given conditions
function checkPalinK ( str , K ) { var N = str . length ; var cntFreq = Array ( 256 ) . fill ( 0 ) ; var i ; for ( i = 0 ; i < N ; i ++ ) { cntFreq [ str [ i ] ] += 1 ; } var cntOddFreq = 0 ; for ( i = 0 ; i < 256 ; i ++ ) { if ( cntFreq [ i ] % 2 == 1 ) { cntOddFreq ++ ; } } if ( cntOddFreq <= ( K + 1 ) ) { return true ; } return false ; } var str = " " ; var K = 2 ; if ( checkPalinK ( str , K ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }