[Java] ✅ O(n) ✅ CLEAN CODE ✅ CLEAR EXPLANATIONS
Approach\n1. Create a char[] chrs = copy of S. You will make operations on this chrs.\n2. Traverse chrs and determine current char and its replacement;\n3. If r
# Approach\n1. Create a char[] chrs = copy of S. You will make operations on this chrs.\n2. Traverse chrs and determine current char and its replacement;\n3. If replacement < ch, set a boolean flag replacement = true and replace current char with replacement\n4. If replacement > ch (eg: replacement of a is z) AND you are in process of replacing, then break immediately.\n    - You have reached the point where you should not replace anymore. Return new String(chrs)\n5. At the end, if you still have not returned, it means you did not make any replacement, because of edge case string "a..a". As you MUST make one replacement, replace the last char with z.\n\n# Complexity\n- Time complexity:$$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:$$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public String smallestString(String s) {\n        char[] chrs = s.toCharArray();\n        char ch, replacement = 0;\n        boolean replacing = false;\n        for (int i = 0; i < s.length(); i++) {\n            ch = s.charAt(i);\n            replacement = (ch == \'a\' ? \'z\' : (char)(ch - 1));\n            if (replacement > ch && replacing) {\n                return new String(chrs);\n            } else if (replacement < ch) {\n                replacing = true;\n                chrs[i] = replacement;\n            }\n        }\n        if (!replacing) {\n            chrs[chrs.length -1] = \'z\';\n        }\n        return new String(chrs);\n    }\n}\n```
['Java']