Python O(n)  Solution with Code Comments
Complexity
Time complexity: O(n)

Space complexity: O(n) - returning string.
Code
# Complexity
- Time complexity: O(n)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: O(n) - returning string.
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```python3 []
class Solution:
    def getSmallestString(self, s: str, k: int) -> str:
        answer = ""
        for i in range(len(s)):
            if s[i] == 'a' or k == 0:
                answer += s[i]
            else:
                # distance from 'a' to the right
                r_dist = ( (26 + ord('a')) - ord(s[i]))

                # initialize to 'z' so that we don't use it
                right_char = 'z'

                # closest achievable distance from s[i] such that char is minimized from left
                l = min(ord(s[i]) - ord('a'), k)

                # If we can reach 'a' by wrapping around, set right char to 'a'
                if r_dist <= k:
                    right_char = 'a'

                # smallest lexigraphic string from the left side.
                left_char = chr( ord(s[i]) - l)
                # Always take the smaller distance to optimal char if they're equal
                if right_char == left_char:
                    answer += left_char
                    k -= min(r_dist, l)
                    
                # Otherwise, take the optimal char and subtract, since we want smallest string.
                elif right_char < left_char:
                    answer += right_char
                    k -= r_dist
                else:
                    answer += left_char
                    k -= l
        
        return answer
```
['Python3']