Easy - Compare Left and Right Distances
Intuition\nSince the task is to return the lexicographically smallest string, so we will try to convert the beginning characters into \'a\', if possible.\n\n# A
# Intuition\nSince the task is to return the lexicographically smallest string, so we will try to convert the beginning characters into \'a\', if possible.\n\n# Approach\n1. It iterates through each character`ch`in the input string`s`.\n3. For each character`ch`, it calculates two values:\n\u2022 `left` : The distance between the character and \'a\' on left side.\n\u2022 `right`: The distance between the character and \'a\' on the right side.\n4. It then calculates`mnn`,which is the minimum of`left`and`right`.\n5. If`k`(the remaining operations) is greater than or equal to `mnn`, it reduces`k`by`mnn`and sets the current character`ch`to \'a\'.\n6. Otherwise, it subtracts `k` from the current character `ch` and break the loop.\n7. Finally, it returns the modified string`s`.\n\n# Complexity\n- Time complexity:  `O(n)`\n\n# Code\n```\nclass Solution\n{\npublic:\n    string getSmallestString(string s, int k)\n    {\n        string ans = s;\n        for (char &ch : s)\n        {\n            int left = ch - \'a\';\n            int right = \'z\' - ch + 1;\n            int mnn = min(left, right);\n            if (k >= mnn)\n            {\n                k -= mnn;\n                ch = \'a\';\n            }\n            else\n            {\n                ch = ch - k;\n                break;\n            }\n        }\n        return s;\n    }\n};\n```
['String', 'Greedy', 'C++']