Best Most Optimal Clean Code
Intuition\n Describe your first thoughts on how to solve this problem. \nThink Greedy\n# Approach\n Describe your approach to solving the problem. \nStarting fr
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThink Greedy\n# Approach\n<!-- Describe your approach to solving the problem. -->\nStarting from the left, try all 26 characters within the distance k, return t when k is exhausted\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n) - one pass\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(1) - extra space\n\n# Code\n```\nclass Solution {\npublic:\n    int dist(char c, char d) {\n        return min(c - d + 26, d - c);\n    }\n\n    string getSmallestString(string s, int k) {\n        int d;\n        for (int i = 0; i < s.size() and k; i++) {\n            for (char c = \'a\'; c <= \'z\'; c++) {\n                d = dist(c, s[i]);\n                if (d <= k) {\n                    k -= d;\n                    s[i] = c;\n                    break;\n                }\n            }\n        }\n        return s;\n    }\n};\n```
['C++']