[Java] ✅ 1MS ✅ 100% ✅ FASTEST ✅ BEST ✅ CLEAN CODE
Approach\n1. The smallest lexic string starts with lowest chars (a) first\n2. Apply a greedy algorithm, trying to lower the first chars while k allows it.\n3. T
# Approach\n1. The smallest lexic string starts with lowest chars (a) first\n2. Apply a greedy algorithm, trying to lower the first chars while k allows it.\n3. Traverse from first :\n    - if k == 0, then you cannot do any modification; append the current letter as it is\n    - else, figure out the min distance from current letter to a : current - \'a\' or 123 - current. \n    - if this distance <= k, reduce k by it and append \'a\'\n    - else if cannot reach a, but a char to the left of current char by k. Append that and reduce k\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```java []\nclass Solution {\n    public String getSmallestString(String s, int k) {\n        StringBuilder stb = new StringBuilder(s.length());\n        char currentChar;\n        for (int i = 0; i < s.length(); i++) {\n            currentChar = s.charAt(i);\n            if (k > 0) {\n                k -= appendAndReduce(stb, currentChar, k);\n            } else {\n                stb.append(currentChar);\n            }\n        }\n        return stb.toString();\n    }\n\n    private int appendAndReduce(StringBuilder stb, char currentChar, int k) {\n        int minDistance = Math.min(123 - currentChar, currentChar - \'a\');\n        if (k >= minDistance) {\n            stb.append(\'a\');\n            return minDistance;\n        } else {\n            stb.append((char)(currentChar - k));\n            return k;\n        }\n    }\n}\n```
['Java']