Get K | Function to return the K - th letter from new String . ; finding size = length of new string S ; get the K - th letter ; Driver Code
def K_thletter ( S , K ) : NEW_LINE INDENT N = len ( S ) NEW_LINE size = 0 NEW_LINE DEDENT ' NEW_LINE INDENT for i in range ( 0 , N ) : NEW_LINE INDENT if S [ i ] . isdigit ( ) : NEW_LINE INDENT size = size * int ( S [ i ] ) NEW_LINE DEDENT else : NEW_LINE INDENT size += 1 NEW_LINE DEDENT DEDENT for i in range ( N - 1 , - 1 , - 1 ) : NEW_LINE INDENT K %= size NEW_LINE if K == 0 and S [ i ] . isalpha ( ) : NEW_LINE INDENT return S [ i ] NEW_LINE DEDENT if S [ i ] . isdigit ( ) : NEW_LINE INDENT size = size // int ( S [ i ] ) NEW_LINE DEDENT else : NEW_LINE INDENT size -= 1 NEW_LINE DEDENT DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT S = " geeks2for2" NEW_LINE K = 15 NEW_LINE print ( K_thletter ( S , K ) ) NEW_LINE DEDENT