# Decoded String at Index : Array + math

`Input: S = "leet2code3", K = 10Output: "o"Explanation: The decoded string is "leetleetcodeleetleetcodeleetleetcode".The 10th letter in the string is "o".`
`Input: S = "ha22", K = 5Output: "h"Explanation: The decoded string is "hahahaha".  The 5th letter is "h".`
`Input: S = "a2345678999999999999999", K = 1Output: "a"Explanation: The decoded string is "a" repeated 8301530446056247680 times.  The 1st letter is "a".`

# Intuition :Work Backwards

`class Solution:    def decodeAtIndex(self, S: str, K: int) -> str:        size = 0        # Find size = length of decoded string        for c in S:            if c.isdigit():                size *= int(c)            else:                size += 1        # print(size)        # print(K)        # print("*****")        for c in reversed(S):                        K %= size            # print(K, size)            if K == 0 and c.isalpha():                return cif c.isdigit():                size /= int(c)            else:                size -= 1`
`"leet2code3"10`
`3610**********10 36*****10.0 12.0*****10.0 11.0*****0.0 10.0`
`"o"`

--

--