Short 2 Step Greedy approach
Intuition\n Describe your first thoughts on how to solve this problem. \nGreedy approach will help here as a lexicographically ordered string will ideally start
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nGreedy approach will help here as a lexicographically ordered string will ideally start with the first character which is a. The key is to find minimum offset distance to character \'a\'.\n\n\n# Approach\n1. since the alphabets are cyclical in order- the character can be closer to a from the first half or second half. Get minimum offset distance through minDiff\n2. A lexicographically ordered string ideally starts with a. take the maximum value of k, if k > minDiff to add \'a\' character to result.\n2. Finally subtract the remaining of whatever k is left. Add the resulting character to the result string\n\n# Complexity\n- Time complexity: O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(N)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n    def getSmallestString(self, s: str, k: int) -> str:\n        res = \'\'\n        for i in range(len(s)):\n            beg = ord(s[i]) - ord(\'a\')\n            end = ord(\'z\') - ord(s[i]) + 1\n        #find closest distance to \'a\'\n            minDiff = min(beg, end)\n        #As long as k > 0 add character \'a\' to string else add whatever remaining k is left to bring character closer to a\n            if k >= minDiff:\n                k -= minDiff\n                res += \'a\'\n            else:\n                offset = ord(s[i]) - k \n                res += chr(offset)\n                k = 0\n        return res\n                \n                \n               \n                \n            \n    \n                \n                \n                \n                \n                \n        \n```
['Python3']