Java O(n) solution
Code\n\nclass Solution {\n    public String smallestString(String s) {\n        char[] arr = s.toCharArray();\n        int i=0;\n        while(i < arr.length &&
# Code\n```\nclass Solution {\n    public String smallestString(String s) {\n        char[] arr = s.toCharArray();\n        int i=0;\n        while(i < arr.length && arr[i] == \'a\')\n            i++;\n        if(i == arr.length)\n            arr[i-1] = \'z\';\n        else {\n            while(i < arr.length) {\n                if(arr[i] == \'a\')\n                    break;\n                \n                arr[i] = (char)(arr[i] - 1);\n                i++;\n            }\n        }\n        \n        return new String(arr);\n    }\n}\n```
['Java']