greedy move from index 0 to n-1 || easy to understand || must see
Code\n\nclass Solution {\npublic:\n    string getSmallestString(string s, int k) {\n          \n          int dis = 0;\n          if(k == 0) return s;\n        
# Code\n```\nclass Solution {\npublic:\n    string getSmallestString(string s, int k) {\n          \n          int dis = 0;\n          if(k == 0) return s;\n          string ans = s;\n          for(int i = 0 ; i < s.length() ; i++){\n            if(dis == k) return ans;\n            if(s[i] == \'a\') continue;\n            \n            //the leeter must have been a bigger letter and \n            //can be changed to a smaller letter with respect to k\n\n            char ch = fun(s,i,k);\n            ans[i] = ch;\n          }\n          return ans;\n    }\n    char fun(string &str , int &idx , int &k){\n         \n            //we will move the left side \n            char ch = str[idx];\n\n            \n            int k1 = k;\n            char ch1 = ch;\n            while(true){    //moving towards left or a\n                if(k1 == 0 or ch1 == \'a\') break;\n                ch1 = char(ch1 - 1);\n                k1 = k1 - 1;\n            }\n\n            //we will move the right side\n            int k2 = k;\n            char ch2 = ch;\n            while(true){   //moving towards right or z\n                if(k2 == 0 or ch2 == \'a\') break;\n                ch2 = char(ch2 + 1);\n                if(ch2 > \'z\') ch2 = \'a\';\n                k2 = k2 - 1;\n            }\n            \n            // cout<<"idx = "<<idx<<" "<<"ch1 = "<<ch1<<" "<<"ch2 = "<<ch2<<endl;\n            // cout<<"idx ="<<idx<<"k1 = "<<k1<<" "<<"k2 = "<<k2<<endl;\n\n            if(ch1 == ch2){\n                k = max(k1,k2);\n                return ch1;\n            }\n            else if(ch1 < ch2){\n                k = k1;\n                return ch1;\n            }\n            else {\n                k = k2;\n                return ch2;\n            }\n            return \'*\';\n    }\n};\n```
['String', 'Greedy', 'C++']