2 Step easy C++ solution ✅ | O(n) Time and O(1) Space | Single pass
Intuition and approach is added as comments in code\n\n# Complexity\n- Time complexity: O(n) \n\n- Space complexity: O(1)\n- If you gets this question in an int
### **Intuition and approach is added as comments in code**\n\n# Complexity\n- Time complexity: O(n) \n\n- Space complexity: O(1)\n- If you gets this question in an interview, inform them that we are manipulating the input string, if you don\'t want me to do this, then I can store its copy which will take O(n) Space\n- Here, n is size of the string\n\n# Code\n```\nclass Solution {\npublic:\n    string smallestString(string s) {\n        int n = s.size();\n        // Place the pointer on 0th index\n        int ptr1 = 0;\n\n        // Increase The pointer until we get some non \'a\' char\n        while(ptr1 < n && s[ptr1++] == \'a\') ptr1++;\n\n        // If we reach the end of string, just convert the last\n        // index to \'z\', as the question asks us to perform the\n        // operation exactly once\n        if(ptr1 == n) s[n-1] = \'z\';\n\n        // If we are not at the end of string, then this loop will execute, \n        // This loop converts all the characters until we gets a \'a\' char.\n        // Ex: It will convert b -> a, bc -> ab, bca -> aba.\n        // The loop will break as soon as we finds a \'a\'\n        while(ptr1 < n && s[ptr1] != \'a\'){\n            s[ptr1] = s[ptr1] - 1;\n            ptr1++;\n        }\n\n        // We now returns the updated String\n        return s;\n    }\n};\n```\n#### **Upvote motivates me to keep uploading the solutions**
['C++']