Easy to understand, explained solution || Python
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# Co
# 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```python3 []\nclass Solution:\n    def getSmallestString(self, s: str, k: int) -> str:        \n        s = list(s)\n        for i in range(len(s)):\n            char = s[i]\n\n            # get the distance between this char, and \'a\'\n            dist = self.distance(char, \'a\')\n            if dist <= k:\n                # if that distance is <= k, then immediately assign \'a\' to\n                # the char, because it is the smallest letter lexicographically\n                s[i] = \'a\'\n                k -= dist\n            else:\n                # otherwise, get the smallest letter that k allows, and break\n                # from the loop as no further changes are allowed for next chars\n                s[i] = chr(ord(char) - k)\n                break\n\n        return "".join(s)\n\n    def distance(self, c1, c2):\n        ord1, ord2 = None, None\n\n        # this part is just to make it easier to know that ord1 < ord2\n        if c1 < c2:\n            ord1, ord2 = ord(c1), ord(c2)\n        else:\n            ord1, ord2 = ord(c2), ord(c1)\n\n        # return the min distance between the two chars, whether that\n        # is by looping over the edge of \'a\' or \'z\', or not\n        return min(ord2 - ord1, ord1 - ord(\'a\') + ord(\'z\') - ord2 + 1)\n```
['Python3']