Simple C++ Solution .
Code\n\nclass Solution {\npublic:\n    string smallestString(string s) {\n        string ans=s; //ans -> copy of s\n        int flag=0,end=0;\n        int n=s.s
# Code\n```\nclass Solution {\npublic:\n    string smallestString(string s) {\n        string ans=s; //ans -> copy of s\n        int flag=0,end=0;\n        int n=s.size();\n        while(end<n){\n            if(end==0 && s[end]==\'a\'){ // if \'a\' at first position then do nothing\n                end++;\n                continue;\n            }   \n            if(s[end]==\'a\' && flag){ // if  found \'a\' and nothing else yet then break , meaning all \'a\' \n                break;\n            }  \n            if(s[end]!=\'a\'){// if other than \'a\' then decrement by 1 ;\n                flag=1;     // mark flag as 1 specifying there is change so that next tym we found\'a\' we break the loop\n                ans[end]--;\n            }\n            end++;   \n        }\n        if(flag==0 ) // if made no changes meaning all \'a\' in string then just swap last position el. with \'z\'\n            ans[n-1]=\'z\';\n        return ans;\n    }\n};\n```
['C++']