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 ; Print the count ; Driver Code
function KthCharacter ( S , N , K ) { var strarray = S . split ( ' ' ) ; strarray . sort ( ) ; var ch = strarray [ K - 1 ] ; var count = 0 ; strarray . forEach ( c => { if ( c == ch ) count ++ ; } ) ; document . write ( count ) ; } var S = " " ; var N = S . length ; var K = 3 ; KthCharacter ( S , N , K ) ;