[C++] Greedy
Code\n\nclass Solution {\npublic:\n    string getSmallestString(string s, int k) {\n        string ans = s;\n        int n = s.size(), i = 0;\n        while (k 
# Code\n```\nclass Solution {\npublic:\n    string getSmallestString(string s, int k) {\n        string ans = s;\n        int n = s.size(), i = 0;\n        while (k > 0 && i < n)\n        {\n            int d = min(s[i] - \'a\', \'z\' - s[i] + 1);\n            if (k > d)\n            {\n                ans[i] = \'a\';\n                k -= d;\n            }\n            else\n            {\n                int c = min(s[i] - \'a\' - k, (s[i] - \'a\' + k) % 26);\n                ans[i] = \'a\' + c;\n                k = 0;\n            }\n            i++;\n        }\n        return ans;\n    }\n};\n```
['Greedy', 'C++']