C++ Easy Explanation Optimal Approach
Approach\nstart with a string of all a\'s of length n as it is the lexicographically smallest string possible\nupdate k as k-n\n\nnow we traverse our string fro
**Approach**\nstart with a string of all a\'s of length n as it is the lexicographically smallest string possible\nupdate k as k-n\n\nnow we traverse our string from right to left and try to fill it with the maximum character possible (this will make sure that we get the lowest characters to the left)\n\n\n**fillling indexes with characters**\n--whenever we get our k>25,\nwe fill that index with z and update k=k-25\n--whenever we get k<25\nwe fill that index with (\'a\'+k)th character and update k=0\n\n**we are using 25 instead of 26 coz our indexex are already filled with value 1 aka character \'a\'**\n\nwe will stop when we traverse all the index or **k becomes 0**\n\n**Code**\nclass Solution {\npublic:\n    string getSmallestString(int n, int k) {\n        \n        string ans(n,\'a\');\n        \n        k=k-n;\n        \n        for(int i=n-1;i>=0;i--)\n        {\n            if(k==0)\n                break;\n            if(k<25)\n            {\n                ans[i]=\'a\'+k;\n                k=0;\n            }\n            else\n            {\n                ans[i]=\'z\';\n                k=k-25;\n            }\n        }\n        return ans;\n    }\n};\n\nPLEASE UPVOTE
['String', 'Greedy', 'C']