🔥Beats 100% - O(n) - Easiest Approach | Clean Code | C++ |
Code\n\nclass Solution {\npublic:\n    string getSmallestString(string s, int k) {\n        for (int i = 0; i < s.size(); i++) \n        {\n            \n      
# Code\n```\nclass Solution {\npublic:\n    string getSmallestString(string s, int k) {\n        for (int i = 0; i < s.size(); i++) \n        {\n            \n            if (s[i] == \'a\')\n                continue;\n\n            int distanceToA = s[i] - \'a\';\n            int cyclicDistanceToA = min(distanceToA, 26 - distanceToA);\n\n            if (k >= cyclicDistanceToA) \n            {\n                s[i] = \'a\';\n                k -= cyclicDistanceToA;\n            } \n            else \n            {\n                s[i] -= k;\n                k = 0;\n            }\n            \n            if (k == 0)\n                break;\n        }\n        \n        return s;\n    }\n};\n\n```
['C++']