Frequency of lexicographically Kth smallest character in the a string | 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 ; Prthe count ; Driver Code
def KthCharacter ( S , N , K ) : NEW_LINE INDENT strarray = [ char for char in S ] ; NEW_LINE strarray . sort ( ) ; NEW_LINE ch = strarray [ K - 1 ] ; NEW_LINE count = 0 ; NEW_LINE for c in strarray : NEW_LINE INDENT if ( c == ch ) : NEW_LINE INDENT count += 1 ; NEW_LINE DEDENT DEDENT print ( count ) ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT S = " geeksforgeeks " ; NEW_LINE N = len ( S ) ; NEW_LINE K = 3 ; NEW_LINE KthCharacter ( S , N , K ) ; NEW_LINE DEDENT