✅ Explained - Simple and Clear Python3 Code✅
Intuition\nThe problem asks us to find the lexicographically smallest string that can be obtained by performing a specific operation on a given string. We need 
# Intuition\nThe problem asks us to find the lexicographically smallest string that can be obtained by performing a specific operation on a given string. We need to replace each character of a non-empty substring with its previous character in the English alphabet. The intuition behind the solution is to identify the substring that needs to be modified and replace its characters accordingly to obtain the desired result.\n\n\n# Approach\nThe solution starts by initializing the length of the input string and a pointer variable \'i\' to keep track of the current position in the string. It then enters a while loop to find the starting position of the substring that needs to be modified.\n\nWithin the loop, it checks if the current character at position \'i\' is equal to \'a\'. If it is, the pointer is incremented, and the loop continues until either the end of the string is reached or a character different from \'a\' is encountered. If the end of the string is reached, it means the entire string consists of \'a\'s. In this case, we replace the last character with \'z\' and return the modified string.\n\nOnce the starting position of the substring is determined, the solution proceeds to find the ending position. It scans the remaining characters of the string from the starting position and stops when it encounters a character that is not \'a\'. The ending position is then stored.\n\nNext, the solution converts the string into a list of characters to make it mutable. It iterates over the range from the starting position to the ending position and replaces each character with its previous character in the English alphabet by decrementing its ASCII value. Finally, it joins the modified characters back into a string and returns the lexicographically smallest string obtained after the operation.\n# Complexity\n- Time complexity:\nThe solution scans the string once to find the starting and ending positions of the substring, which takes O(n) time, where \'n\' is the length of the string. The conversion of the string into a list and the character replacement process also take O(n) time. Therefore, the overall time complexity is O(n).\n\n\n- Space complexity:\n The solution converts the string into a list, which requires O(n) additional space. The rest of the operations are done in-place, so the space complexity is O(n).\n\n\n# Code\n```\nclass Solution:\n    def smallestString(self, s: str) -> str:\n        n = len(s)\n        i=0\n        while s[i]==\'a\' and i<n:\n            i+=1\n            if i==n:\n                return s[:len(s)-1]+\'z\'\n        start=i\n        while  i<n :\n            if s[i]!=\'a\' :\n                i+=1\n            else:\n                break\n        end=i\n        xx=[*str(s)]\n        for i in range(start,end):\n            xx[i] = chr(ord(xx[i]) - 1)\n        return "".join(xx)\n```
['Python3']