✅Image explantion [C++, Java, Python]
\n\n\nT.C: O(N)\nS.C: O(1)\n\nC++\n\n\nstring smallestString(string s) {\n        int start=0;\n        while(s[start]==\'a\')start++;    // skip if \'a\' is oc
![image](https://assets.leetcode.com/users/images/8468ff3a-e18e-4c31-9a44-fdf82f2f87b5_1686456384.950873.png)\n![image](https://assets.leetcode.com/users/images/fae295a2-bb3a-4b45-97c2-e1992ab0c253_1686456508.8339894.png)\n\n**T.C: O(N)\nS.C: O(1)**\n\n**C++**\n\n```\nstring smallestString(string s) {\n        int start=0;\n        while(s[start]==\'a\')start++;    // skip if \'a\' is occuring as substring from starting\n        if(start==s.size()){                 // if reaches to last so we have to do exactly 1 operation so just change last one\n            s[s.size()-1]=\'z\';              \n        }\n        for(int i=start; i<s.size(); i++){\n            if(s[i]==\'a\')return s;        // if get \'a\' in middle we will not able to change further string since \'a\' will convert in \'z\' which well not make string smaller\n            else{\n                s[i]=s[i]-1;   // else not \'a\' means we can easily go prev to get smaller character\n            }\n        }\n        return s;\n    }\n```\n\n**JAVA**\n\n```\npublic String smallestString(String s) {\n    int start = 0;\n    while (s.charAt(start) == \'a\') {\n        start++; // skip if \'a\' is occurring as a substring from the start\n    }\n    if (start == s.length()) {\n        // if it reaches the last character, we have to do exactly 1 operation, so just change the last one\n        char[] chars = s.toCharArray();\n        chars[s.length() - 1] = \'z\';\n        return new String(chars);\n    }\n    char[] chars = s.toCharArray();\n    for (int i = start; i < s.length(); i++) {\n        if (chars[i] == \'a\') {\n            return s; // if we encounter \'a\' in the middle, we won\'t be able to change the string further since \'a\' will convert to \'z\' which will not make the string smaller\n        } else {\n            chars[i] = (char) (chars[i] - 1); // if it\'s not \'a\', we can easily go to the previous character to get a smaller character\n        }\n    }\n    return new String(chars);\n}\n\n```\n**PYTHON**\n\n```\nclass Solution:\n    def smallestString(self, s):\n        s = list(s)  # Convert the string to a list of characters for efficient updates\n        start = 0\n        while start < len(s) and s[start] == \'a\':\n            start += 1  # Skip if \'a\' is occurring as a substring from the starting\n        if start == len(s):  # If reaches the end, we have to do exactly 1 operation, so just change the last character\n            s[-1] = \'z\'\n        for i in range(start, len(s)):\n            if s[i] == \'a\':\n                return \'\'.join(s)  # Convert the list back to a string\n            else:\n                s[i] = chr(ord(s[i]) - 1)  # Replace non-\'a\' characters with the previous character\n        return \'\'.join(s)  # Convert the list back to a string\n\n\n```
[]