1
# Runtime: 1870 ms (Top 22.43%) | Memory: 15.5 MB (Top 41.47%)3
def getSmallestString(self, n: int, k: int) -> str:4
ans = ["a"] * n # Initialize the answer to be 'aaa'.. length n5
val = n # Value would be length as all are 'a'7
for i in range(n - 1, -1, -1):10
): # if value has reached k, we have created our lexicographically smallest string12
val -= 1 # reduce value by one as we are removing 'a' and replacing by a suitable character15
) # replace with a character which is k - value or 'z'18
) # add the value of newly appended character to value20
return "".join(ans) # return the ans string in the by concatenating the list