Using 2 flags most optimal solution
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    string smallestString(string s) {\n        int n = s.size();\n        bool found = false;\n        bool change = false;\n        for(int i=0;i<n;i++){\n            if(s[i]!=\'a\'){\n                s[i] = s[i]-1;\n                change = true;\n            }\n            else{\n                if(change){\n                    return s;\n                }\n                found = true;\n            }\n        }\n        if(!change){\n            s[n-1] = \'z\';\n            return s;\n        }\n        return s;\n    }\n};\n```
['C++']