C➕➕ Easy to understand code || T.C. O(n) & S.C. O(1)
\n# Approach\n Describe your approach to solving the problem. \nIf string only contains \'a\': \n1. Change last \'a\' to \'z\'\n\nIf string contains other chara
\n# Approach\n<!-- Describe your approach to solving the problem. -->\n*If string only contains* ***\'a\'***: \n1. Change last \'a\' to \'z\'\n\n*If string contains* ***other characters*** : \n1. Skip initial \'a\'\n2. Change all characters to its previous characters until found and \'a\' or you have traversed the whole string.\n\n# Complexity\n- Time complexity:\n$$O(n)$$\n\n- Space complexity:\n$$O(1)$$\n\n# Code\n```\nclass Solution {\npublic:\n    string smallestString(string s) {\n        int i = 0;\n        bool flag =false;\n        while(s[i]==\'a\' && i<s.size()){\n            i++;\n            continue;\n        }\n        \n        while(s[i]!=\'a\' && i<s.size()){\n            flag = true;\n            s[i]=s[i]-1;\n            i++;\n        }\n        \n        if(flag == false)s[s.size()-1]=\'z\';\n        return s;\n    }\n};\n```
['C++']