Simple C++ Solution in o(N) TC
Intuition\n Describe your first thoughts on how to solve this problem. \n\n\n# Approach\n Describe your approach to solving the problem. \nThe code replaces the
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nThe code replaces the first non-\'a\' character encountered in the input string s with the character that comes before it in the ASCII sequence. If all characters in s are \'a\', it replaces the last character with \'z\'.\n\n1. If s has only one character, it is replaced with \'z\' if it is \'a\', otherwise, its ASCII value is decremented by 1.\n2. If s has multiple characters, the first non-\'a\' character is replaced with the character that comes before it in the ASCII sequence.\n3. If all characters in s are \'a\', the last character is replaced with \'z\'.\n4. The modified string is returned as the result.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n    o(N)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n    o(1)\n\n# Code\n```\nclass Solution\n{\n\tpublic:\n\t\tstring smallestString(string s)\n\t\t{\n\t\t\tbool flag = 0;\n\t\t\tif (s.size() == 1)\n\t\t\t{\n\t\t\t\tif (s[0] == \'a\') s[0] = \'z\';\n\t\t\t\telse s[0] = s[0] - 1;\n\t\t\t\treturn s;\n            }\n\t\t\tfor (int i = 0; i < s.size(); i++)\n\t\t\t{\n\t\t\t\tif (s[i] != \'a\')\n\t\t\t\t{\n\t\t\t\t\tflag = 1;\n\t\t\t\t\ts[i] = s[i] - 1;\n\t\t\t\t}\n\t\t\t\telse if (flag) break;\n\t\t\t}\n\t\t\tif (flag == false)\n\t\t\t\ts[s.size() - 1] = \'z\';\n\t\t\treturn s;\n\t\t}\n};\n\n```
['C++']