1663. Smallest String With A Given Numeric Value

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1663

class Solution:
    def getSmallestString(self, n: int, k: int) -> str:
        res = ['a'] * n
        i, d = n - 1, k - n
        while d > 25:
            res[i] = 'z'
            d -= 25
            i -= 1
        res[i] = chr(ord(res[i]) + d)
        return ''.join(res)