Count of K | C # program for the above approach ; To store the frequency array ; Function to check palindromic of of any subString using frequency array ; Initialise the odd count ; Traversing frequency array to compute the count of characters having odd frequency ; Returns true if odd count is atmost 1 ; Function to count the total number subString whose any permutations are palindromic ; Computing the frequency of first K character of the String ; To store the count of palindromic permutations ; Checking for the current window if it has any palindromic permutation ; Start and end point of window ; Decrementing count of first element of the window ; Incrementing count of next element of the window ; Checking current window character frequency count ; Return the final count ; Driver Code ; Given String str ; Window of size K ; Function Call
using System ; class GFG { static int [ ] freq = new int [ 26 ] ; static bool checkPalindrome ( ) { int oddCnt = 0 ; foreach ( int x in freq ) { if ( x % 2 == 1 ) oddCnt ++ ; } return oddCnt <= 1 ; } static int countPalindromePermutation ( char [ ] s , int k ) { int i = 0 ; for ( i = 0 ; i < k ; i ++ ) { freq [ s [ i ] - 97 ] ++ ; } int ans = 0 ; if ( checkPalindrome ( ) ) { ans ++ ; } int j = k ; i = 0 ; while ( j < s . Length ) { freq [ s [ i ++ ] - 97 ] -- ; freq [ s [ j ++ ] - 97 ] ++ ; if ( checkPalindrome ( ) ) { ans ++ ; } } return ans ; } public static void Main ( String [ ] args ) { String str = " abbaca " ; int K = 3 ; Console . Write ( countPalindromePermutation ( str . ToCharArray ( ) , K ) + " STRNEWLINE " ) ; } }