Kth character after replacing each character of String by its frequency exactly X times | Python3 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 ; Given Input ; Function Call
import math NEW_LINE def FindKthChar ( Str , K , X ) : NEW_LINE INDENT ans = ' ▁ ' NEW_LINE Sum = 0 NEW_LINE for i in range ( len ( Str ) ) : NEW_LINE INDENT digit = ord ( Str [ i ] ) - 48 NEW_LINE Range = int ( math . pow ( digit , X ) ) NEW_LINE Sum += Range NEW_LINE if ( K <= Sum ) : NEW_LINE INDENT ans = Str [ i ] NEW_LINE break NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT Str = "123" NEW_LINE K = 9 NEW_LINE X = 3 NEW_LINE ans = FindKthChar ( Str , K , X ) NEW_LINE print ( ans ) NEW_LINE