CPP CODE :
Code\n\nclass Solution {\npublic:\n    string smallestString(string s) {\n       map<char,int> mp,mp1;string ans = "";\n        int start= 0 ,end = 0;\n        
# Code\n```\nclass Solution {\npublic:\n    string smallestString(string s) {\n       map<char,int> mp,mp1;string ans = "";\n        int start= 0 ,end = 0;\n        if(s[0] == \'a\'){\n            for(int i = 0; i < s.size(); i++)\n                mp1[s[i]]++;\n            if(mp1.size() == 1){\n              for(int i = 0; i < s.size()-1; i++)\n                  ans+=\'a\';\n                  ans+=\'z\';\n                return ans;\n            }\n            else goto end;\n        }\n        end: for(int i = 0; i < s.size(); i++){\n            mp[s[i]]++;\n            if(s[i] == \'a\'){\n            if(mp[\'a\'] >= 1 && i != 0 && mp.size() > 1){\n                for(int j = i; j < s.size(); j++)\n                    ans+=s[j];\n                break;\n            }\n                else ans+=s[i];\n            }\n            else if(s[i] != \'a\'){\n                ans+=(--s[i]);\n            }\n        }\n        return ans;\n    }\n};\n```
['C++']