Lexicographically smallest string after substring operation | C++ Solution | Easy 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(N)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    string smallestString(string s) {\n\n        int n=s.length();\n        string str=s;\n        int i=0;\n\n        //case1: for the cases where there is any char before \'a\'\n        //so we can easily replace them to get the lexigrahically \n        //smallest one\n\n        while(i<n && s[i]!=\'a\')\n        {\n            s[i]=(int)s[i]-1;\n            i++;\n        }\n        if(str!=s) return s;\n\n        //case2: for the cases where there is some occurrence of \'a\'\n        //and then any char(substring)\n        while(i<n && s[i]==\'a\') i++;\n        while(i<n && s[i]!=\'a\') \n        {\n            s[i]=(int)s[i]-1;\n            i++;\n        }\n        if(str!=s) return s;\n\n        //case3: for the cases where string is full of \'a\'\n        //and as given in question we\'ve to perform operation\n        //so for the smallest we can directly change its last char to \'z\'\n        s[n-1]=\'z\';\n        return s;\n        \n    }\n};\n```
['C++']