Made Easy | Greedy | Time: O(n) | Space: O(1)
Intuition\n\nSince we need to choose a substring to make it lexo smaller, we cant \nchose a if its in the beggining, since it is reduced to z. \nSo, skip all a\
# Intuition\n```\nSince we need to choose a substring to make it lexo smaller, we cant \nchose a if its in the beggining, since it is reduced to z. \nSo, skip all a\'s first, then go on decreasing till you found \nanother a (why? all others are reduced by -1 but a is reduced to z,\nmaking it lexo bigger).\nNote: Dont forget about all a\'s case. (since we need to pick one\n non-empty substring for sure)\n```\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n```\nTraversing the string, lmao\n```\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        // smallest substring from start\n        int n=s.size(), i=0;\n        // skip till all a\'s\n        while(i<n && s[i]==\'a\') i++;\n        // all are a, make last one (since cant be empty substring)\n        if(i==n){\n            s.back()=\'z\';\n            return s;\n        }\n        // otherwise from here go till a\n        while(i<n && s[i]!=\'a\'){\n            s[i]-=1;\n            i++;\n        }\n        return s;\n    }\n};\n```
['C++']