java very efficient solution with comment
\nclass Solution {\n    public String smallestString(String str) {\n        \n        StringBuilder st = new StringBuilder(str);\n        \n        int i;\n    
```\nclass Solution {\n    public String smallestString(String str) {\n        \n        StringBuilder st = new StringBuilder(str);\n        \n        int i;\n        for(i=0;i<st.length();i++){   // if str = "aaaaabnm" i.e starting with \'a\' than we continue till \'a\' not come in string.\n            \n            if(st.charAt(i)==\'a\')                \n                continue;\n            else \n                break;\n        }\n        \n        if(i==st.length())           // if str like  = "aaaaa" than its output is aaaaz \n           st.setCharAt(i - 1, \'z\');\n        \n        \n        for(int k=i;k<st.length();k++)//if str is like "mnkajkl" than we break at \'a\' because \'a\' is change to \'z\' which is not lexo. smaller\n        {\n            if(st.charAt(k)==\'a\')            \n                break;\n            else{\n               st.setCharAt(k, (char) (st.charAt(k) - 1));\n            }\n        }\n        \n        return st.toString();\n    }\n}\n```
[]