Beats 100% simple iteration through string
Intuition\n Describe your first thoughts on how to solve this problem. \n1. Initialization:\nDetermine the length n of the string s.\nIf k is zero, return the o
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n1. Initialization:\nDetermine the length n of the string s.\nIf k is zero, return the original string as no operations are allowed.\n\n2. Iterate Over the String:\nLoop through each character in the string from left to right. The earlier in the string a change is made, the more it can affect the lexicographical order, so prioritize changes starting from the beginning.\n3. Determine Minimum Change:\nFor each character s[i], calculate the minimum of either reducing s[i] to \'a\' directly (s[i] - \'a\') or wrapping around the alphabet to \'a\' (26 - (s[i] - \'a\')).\n\n4. Perform the Change:\nIf changing the current character to \'a\' uses fewer or equal operations than k, make the change, reduce k by the number of operations used, and set s[i] to \'a\'.\nIf changing the character to \'a\' would exceed the remaining operations k, just decrease the character by k positions in the alphabet and set k to 0.\n5. Handle Early Termination:\nIf k reaches zero during the iteration, break out of the loop early since no further changes can be made.\n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    string getSmallestString(string s, int k) {\n        int n=s.size();\n        if(k==0)return s;\n        // return "";\n        for(int i=0;i<n;i++){\n            if(k==0){\n                break;\n            }\n            int x=min((s[i]-\'a\'),(26-(s[i]-\'a\')));\n            if(s[i]==\'a\'){\n                continue;\n            }\n            else if(x<=k){\n                k-=x;\n                s[i]=\'a\';\n            }\n            // else if(26-((s[i]-\'a\')+k)<=0){\n            //     k=k-(26-(s[i]-\'a\'));\n            //     s[i]=\'a\';\n            // }\n            else{\n                s[i]=s[i]-k;\n                k=0;\n            }\n        }\n        return s;\n    }\n};\n```
['C++']