Java Solution 💚💚 | O(n) | Easy Solution
Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(n)\n\n# Code\n\nclass Solution {\n    public String smallestString(String s) {\n        int i = 0
# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(n)\n\n# Code\n```\nclass Solution {\n    public String smallestString(String s) {\n        int i = 0;\n\n        while(i < s.length() && s.charAt(i) == \'a\')\n            i++;\n\n        int k = i;\n\n        while(k < s.length() && s.charAt(k) != \'a\')\n            k++;\n\n        if(i == s.length())\n            return s.substring(0, s.length()-1) + \'z\';\n\n        StringBuilder str = new StringBuilder("");\n\n        for(int j = 0; j < i; j++)\n            str.append("a");\n\n        for(int j = i; j < k; j++)\n            str.append((char)(s.charAt(j)-1));\n\n        for(int j = k; j < s.length(); j++)\n            str.append(s.charAt(j));\n\n        return str.toString();\n    }\n}\n// UP-VOTE IF HELPFUL\n```
['String', 'Greedy', 'Java']