[Python] Simple solution - Greedy - O(N) [Explanation + Code + Comment]
The lexicographically smallest string of length n could be \'aaa\'.. of length n\nThe constraint is that the numeric value must be k.\nTo satisfy this constrain
The lexicographically smallest string of length n could be \'aaa\'.. of length n\nThe constraint is that the numeric value must be k.\nTo satisfy this constraint, we will greedily add either \'z\' or character form of (k - value) to the string.\n\nFor eg. \nn = 3, k = 32\nInitially, ans = \'aaa\', val = 3, i =2\nSince val!=k\nans = \'aaz\', val = 28, i = 1\nSince, val!=k\nk - val = 4\nans = \'adz\', val = 0 \nSince, val == k\nbreak\n\nFinal answer  = \'adz\'\n\nRunning time: O(N)\nMemory: O(1)\n\n```\nclass Solution:\n    def getSmallestString(self, n: int, k: int) -> str:\n        ans = [\'a\']*n  # Initialize the answer to be \'aaa\'.. length n\n        val = n           #Value would be length as all are \'a\'\n        \n        for i in range(n-1, -1, -1):    \n            if val == k:           # if value has reached k, we have created our lexicographically smallest string\n                break\n            val -= 1                # reduce value by one as we are removing \'a\' and replacing by a suitable character\n            ans[i] = chr(96 + min(k - val, 26))   # replace with a character which is k - value or \'z\'\n            val += ord(ans[i]) - 96                     # add the value of newly appended character to value\n            \n        return \'\'.join(ans)                                 # return the ans string in the by concatenating the list\n```
['Greedy', 'Python', 'Python3']