text: Kth character after replacing each character of String by its frequency exactly X times | C # program for the above approach ; Function to find the Kth character after X days ; Variable to store the KthChar ; Traverse the string ; Convert char into int ; Calculate characters ; If K is less than sum than ans = str [ i ] ; Return answer ; Driver Code ; Given Input ; Function Call
code: using System ; using System . Collections . Generic ; class GFG { static char FindKthChar ( string str , int K , int X ) { char ans = ' ▁ ' ; int sum = 0 ; for ( int i = 0 ; i < str . Length ; i ++ ) { int digit = ( int ) str [ i ] - 48 ; int range = ( int ) Math . Pow ( digit , X ) ; sum += range ; if ( K <= sum ) { ans = str [ i ] ; break ; } } return ans ; } public static void Main ( ) { string str = "123" ; int K = 9 ; int X = 3 ; char ans = FindKthChar ( str , K , X ) ; Console . Write ( ans ) ; } }