JAVA | Simple Linear Solution | using SetBuilder
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# Co
# 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        StringBuilder str = new StringBuilder();\n        boolean changed = false, putAsItIs = false;\n\n        for(char c : s.toCharArray()) {\n            if(c == \'a\') {\n                str.append(c);\n                if(changed) {\n                    putAsItIs = true;\n                }\n            } else {\n                if(putAsItIs) {\n                    str.append(c);\n                } else {\n                    changed = true;\n                    str.append((char)(c - 1));\n                }\n            }\n        }\n        if(!changed) {\n            str.setCharAt(str.length() - 1 , \'z\');\n        }\n        return str.toString();\n    }\n}\n\n- Do Upvote if this helps \u2B06\uFE0F \uD83D\uDC4D\uD83C\uDFFB \n```
['Java']