Python3 || O(n) || 3ms beats 100%
Intuition\n- Check the steps needed to get each letter to a starting from left\n- At each iteration, reduce k by no. of steps\n- If no. of steps>=k, then we red
# Intuition\n- Check the steps needed to get each letter to ```a``` starting from left\n- At each iteration, reduce ```k``` by no. of steps\n- If no. of steps>=k, then we reduce the letter by ```k``` steps and terminate the loop. \n\n# Complexity\n- Time complexity: O(n)\n\n# Code\n```python3 []\nclass Solution:\n    def getSmallestString(self, s: str, k: int) -> str:\n        # make each letter as small as possible starting from left\n\n        ls = list(s)\n\n        for i in range(len(ls)):\n            letter = ls[i]\n\n            #check if getting to a is faster from front or back\n            \n            diff = min(ord(letter)-ord(\'a\'), ord(\'z\')-ord(letter)+1) \n            if k-diff<0:\n                ls[i] = chr(ord(letter) - k)\n            else:\n                ls[i] = \'a\'\n\n            k-=diff\n            if k <= 0:\n                break\n\n        return "".join(ls)\n```\n\n![image.png](https://assets.leetcode.com/users/images/f71c5e93-5471-4f25-ac33-e2e409fe6aa6_1729759766.0712812.png)\n
['Python3']