Frequency of lexicographically Kth smallest character in the a string | C # program to implement the above approach ; Function to find the frequency of the lexicographically Kth smallest character ; Convert the string to array of characters ; Sort the array in ascending order ; Store the Kth character ; Store the frequency of the K - th character ; Count the frequency of the K - th character ; Print the count ; Driver Code
using System ; class GFG { public static void KthCharacter ( string S , int N , int K ) { char [ ] strarray = S . ToCharArray ( ) ; Array . Sort ( strarray ) ; char ch = strarray [ K - 1 ] ; int count = 0 ; foreach ( char c in strarray ) { if ( c == ch ) count ++ ; } Console . Write ( count ) ; } public static void Main ( ) { string S = " geeksforgeeks " ; int N = S . Length ; int K = 3 ; KthCharacter ( S , N , K ) ; } }