beats 98% with simple and intuitive python3 solution
Intuition\nTo find lexicographically smallest string we should look for first occurance of character which is not \'a\'.Once, we find that character we start lo
# Intuition\nTo find lexicographically smallest string we should look for first occurance of character which is not \'a\'.Once, we find that character we start looking for the last occurance of character which is not \'a\' or check if\'s not the end of the string.\n\n# Complexity\n- Time complexity:\nO(n) -> Because we are looping through all the characters once to get the first and last occurance of not \'a\'.\n\n- Space complexity:\nO(n) -> For keeping the char arr.\n\n# Code\n```python3 []\nclass Solution:\n    def smallestString(self, s: str) -> str:\n        char_arr = list(s)\n\n        len_s = len(s)\n        i = 0\n        first_occurence_of_non_a = -1\n        last_occurence_of_non_a = -1\n        while i < len_s:\n            if char_arr[i] != \'a\':\n                first_occurence_of_non_a = i\n                i += 1\n                # once first occurence is found look for last one.\n                while i < len_s and char_arr[i] != \'a\':\n                    i += 1\n                last_occurence_of_non_a = i - 1\n                break\n            else:\n                i += 1\n        \n        # if all characters are \'a\', just change the last character of the string with \'z\', since we have to perform the change.\n        if first_occurence_of_non_a == -1:\n            char_arr[-1] = \'z\'\n        else:\n        # update all the characters b/w first and last not \'a\'\n            for i in range(first_occurence_of_non_a, last_occurence_of_non_a + 1):\n                char_arr[i] = chr(ord(char_arr[i]) - 1)\n        \n        return "".join(char_arr)\n\n```
['Python3']