[C++, Python, Javascript] Easy Solution w/ Explanation | beats 100% / 100%
(Note: This is part of a series of Leetcode solution explanations (index). If you like this solution or find it useful, please upvote this post.)\n\n---\n\nIdea
*(Note: This is part of a series of Leetcode solution explanations ([**index**](https://dev.to/seanpgallivan/leetcode-solutions-index-57fl)). If you like this solution or find it useful,* ***please upvote*** *this post.)*\n\n---\n\n***Idea:***\n\nThe basic idea is simple: in order for the string to be as lexigraphically "small" as it can be, you want to move as much of the "weight" towards the rear of the string as possible. \n\nThat means you want as many "**z**"s at the end of the answer and as many "**a**"s at the beginning of the answer as you can get. This also means that there will only be at most one character that is neither an "**a**" or a "**z**".\n\nFirst, remove **n** from **k** in order to leave yourself "room" to fill the remaining space with "**a**"s when you\'re done. This is as if you\'re spending **n** value of **k** to initially fill each position with an "**a**". After that, each character will be considered by how much of an increase it is over "**a**", thus a "**z**" has a value of **25**, because it\'s **25** "more" than an "**a**". That also coincidentally makes thing easier with a **0**-indexed alphabet reference string.\n\nThen start with as many "**z**"s as you can fit in **k**, and use any leftover **k** for the middle character. Then fill out the start of **ans** with "**a**"s.\n\n---\n\n***C++ Code:***\n\nThe best result for the code below is **20ms / 28.4MB** (beats 100%)\n```c++\nclass Solution {\n    public:\n        string getSmallestString(int n, int k) {\n            k -= n;\n            string alpha = "_bcdefghijklmnopqrstuvwxy_";\n            string ans = std::string(~~(k / 25), \'z\');\n            if (k % 25) {\n                ans = alpha[k % 25] + ans;\n            }\n            return std::string(n - ans.size(), \'a\') + ans;\n        }\n    };\n```\n\n---\n\n***Python Code:***\n\nThe best result for the code below is **16ms / 13.9MB** (beats 100% / 100%)\n```python\nclass Solution(object):\n    def getSmallestString(self, n, k):\n        k -= n\n        alpha = \'_bcdefghijklmnopqrstuvwxy_\'\n        ans = \'z\' * (k // 25)\n        if k % 25:\n            ans = alpha[k % 25] + ans\n        return \'a\' * (n - len(ans)) + ans\n```\n\n---\n\n***Javascript Code:***\n\nThe best result for the code below is **80ms / 44.1MB** (beats 100% / 100%)\n```javascript\nvar getSmallestString = function(n, k) {\n    k -= n\n    let alpha =\'_bcdefghijklmnopqrstuvwxy_\',\n        ans = \'z\'.repeat(~~(k / 25))\n    if (k % 25) ans = alpha[k % 25] + ans\n    return ans.padStart(n, \'a\')\n};\n```
['C', 'Python', 'JavaScript']