C++ Solution
Complexity\n- Time complexity:\n Add your time complexity here, e.g. O(n) \nThe time complexity of the given code is O(n), where n is the length of the input st
# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nThe time complexity of the given code is O(n), where n is the length of the input string "s".\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nThe space complexity of the code is O(n) as well. This is because a new string "ans" is created to store the updated string, which requires additional space proportional to the length of the input string "s".\n  \n\n# Code\n```\nclass Solution {\npublic:\n    string smallestString(string s) {\n        int n=s.length();\n        string ans=s;\n        int i=0;\n        while(i<n && s[i]==\'a\'){\n            i++;\n        }\n        if(i==n){\n            ans[n-1]=\'z\';\n            return ans;\n        }\n        int j=i;\n        while(j<n && s[j]!=\'a\'){\n            j++;\n        }\n        for(int k=i;k<j;k++){\n            ans[k] = ans[k] - 1;\n        }\n        return ans;\n    }\n};\n```
['C++']