Easy Java Code O(n) solution beats 95%
\n# Approach\n Describe your approach to solving the problem. \nMake a char Array and just check 2 conditons -:\n\n1- If the first idx of the string is \'a\' th
\n# Approach\n<!-- Describe your approach to solving the problem. -->\nMake a char Array and just check 2 conditons -:\n\n1- If the first idx of the string is \'a\' then count the idx until which it appears and if count of idx is equals to the len of str then replace the last character \'a\' from \'z\'.\n\n2-If first idx is not \'a\' then run a loop until which it doesn\'t appear and change all the characters to it\'s preceding character which can be coded like ----> ch[i] = (char)(ch[i]-1);\n\n                    \n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\n    public String smallestString(String s) {\n        char ch[] = s.toCharArray();\n        int i=0;\n        if(ch[0]==\'a\'){\n            while(i<ch.length && ch[i]==\'a\') i++;\n            if(i==ch.length){\n                ch[i-1] = \'z\';\n                return String.valueOf(ch);\n            }\n        }\n        if(ch[i]!=\'a\'){\n            while(i<ch.length && ch[i]!=\'a\'){\n                ch[i] = (char)(ch[i]-1);\n                i++;\n            }\n        }\n        return String.valueOf(ch);\n    }\n}\n```
['Java']