Easy To Understand
Approach\n- Create a string of size N contanining only \'a\', Because we need Lexicographical String.\n- calculate the cyclic distance, check :- \n1. If less th
# Approach\n- Create a string of size N contanining only \'a\', Because we need Lexicographical String.\n- calculate the cyclic distance, check :- \n1. If less than k, may that character remain same (i.e,\'a\').\n2. else if(k>0) then choose the character, which has distance equal to k.\n3. else make remaining characters as answer, Because we cannot change those character.\n\n# Complexity\n- Time complexity:\n    $$O(n)$$\n\n- Space complexity:\n    $$O(1)$$\n\n# Code\n```\nclass Solution {\npublic:\n    int dist(char a,char b)\n    {\n        int d = abs(b-a);\n        return min(d,26-d);\n              \n    }\n    char sm(char g,int k)\n    {\n        return ((g-\'a\'-k+26)%26 + \'a\');\n    }\n    string getSmallestString(string s, int k) {\n        int n = s.length();\n        string ans = string(n,\'a\');\n        \n        for(int i= 0;i < n  ;i++)\n            if(dist(s[i],ans[i]) <= k)\n                k-=dist(s[i],ans[i]);\n            else if(k>0)\n            {\n                ans[i] = sm(s[i],k);\n                k = 0;\n            }\n            else\n                ans[i] = s[i];\n        \n\n        \n        return ans;\n    }\n};\n```
['C++']