Simple C++ | Easy to understand | Beats 100%
Approach\nSince, we want to get the lexicograpically sorted, we can think of greedy approach of trying to keep the initial characters smaller. \n\n# Complexity\
# Approach\nSince, we want to get the lexicograpically sorted, we can think of greedy approach of trying to keep the initial characters smaller. \n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    string getSmallestString(string s, int k) {\n        for(int i = 0; i < s.size(); i++) {\n            if (k > 0) {\n                s[i] = getSmallestCharacter(s[i], k);\n            }\n        }\n        return s;\n    }\n\n    char getSmallestCharacter(char c, int &k) {\n        int leftDist = c - \'a\', rightDist = (\'z\' - c) + 1;\n        int mn = min(leftDist, rightDist);\n        if (k >= mn) {\n            k -= mn;\n            return \'a\';\n        }\n        char res =  c - k;\n        k = 0;\n        return res;\n    }\n};\n```
['C++']