Count of Palindromic Strings possible by swapping of a pair of Characters | C # Program to implement the above approach ; Function to return the count of possible palindromic Strings ; Stores the frequencies of each character ; Stores the length of the String ; Increase the number of swaps , the current character make with its previous occurrences ; Increase frequency ; Driver Code
using System ; class GFG { static long findNewString ( String s ) { long ans = 0 ; int [ ] freq = new int [ 26 ] ; int n = s . Length ; for ( int i = 0 ; i < ( int ) s . Length ; ++ i ) { ans += freq [ s [ i ] - ' a ' ] ; freq [ s [ i ] - ' a ' ] ++ ; } return ans ; } public static void Main ( String [ ] args ) { String s = " aaabaaa " ; Console . Write ( findNewString ( s ) ) ; } }