Intuitive Java Solution
Intuition\n Describe your first thoughts on how to solve this problem. \n- To get lexicographically smallest, firstly make as many characters == \'a\' as possib
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- To get lexicographically smallest, firstly make as many characters == \'a\' as possible from left of the string. Then if we dont have enough \'k\' to reach \'a\', then reach the lowest possible character by utilizing all the \'k\' on that character\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\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 getSmallestString(String s, int k) {\n        // System.out.println(distance(\'a\', \'z\'));\n        int i=0, sum=0;\n        StringBuilder sb= new StringBuilder(s);\n        while(i<s.length() && sum + distance(\'a\', s.charAt(i)) <= k){\n            sb.setCharAt(i, \'a\');\n            k-=distance(\'a\', s.charAt(i));\n            i++;\n        }\n        if(i<s.length()){\n            char ch= s.charAt(i);\n            int n= Math.min((ch-\'a\' + k)%26 ,(ch-\'a\' - k +26)%26);\n            sb.setCharAt(i, (char)(n+\'a\'));\n        }\n\n        return sb.toString();\n    }\n\n\n    int distance(char a, char b){\n        return Math.min(Math.abs((a-\'a\')- (b-\'a\')), Math.abs((26 + (a-\'a\'))-(b-\'a\')));\n    }\n}\n```
['Java']