[Java/Python 3] Two O(n) codes w/ brief explanation and analysis.
Mehtod 1: Greedily reversely place values\n\n1. Make sure each value of the n characters is at least  1: initialized all as \'a\';\n2. Put as more value at the 
**Mehtod 1: Greedily reversely place values**\n\n1. Make sure each value of the n characters is at least  `1`: initialized all as `\'a\'`;\n2. Put as more value at the end of the String as possible.\n```java\n    public String getSmallestString(int n, int k) {\n        k -= n;\n        char[] ans = new char[n];\n        Arrays.fill(ans, \'a\');\n        while (k > 0) {\n            ans[--n] += Math.min(k, 25);\n            k -= Math.min(k, 25);\n        }\n        return String.valueOf(ans);\n    }\n```\n```python\n    def getSmallestString(self, n: int, k: int) -> str:\n        ans = [\'a\'] * n\n        k -= n\n        while k > 0:\n            n -= 1 \n            ans[n] = chr(ord(\'a\') + min(25, k))\n            k -= min(25, k)\n        return \'\'.join(ans)\n```\n\n**Analysis:**\nTime & space: O(n)\n\n----\n**Method 2: Math**\nCompute the total number of `z` at the end, and the number of not `a` characters right before those `z`: `r`; The remaining are `a`\'s .\n```java\n    public String getSmallestString(int n, int k) {\n        int z = (k - n) / 25, r = (k - n) % 25;\n        return (z == n ? "" : "a".repeat(n - z - 1) + (char)(\'a\' + r)) + "z".repeat(z);\n    }\n```\n```python\n    def getSmallestString(self, n: int, k: int) -> str:\n        z, r = divmod(k - n, 25)\n        return (\'\' if z == n else \'a\' * (n - z - 1) + chr(ord(\'a\') + r)) + \'z\' * z\n```\nThe above codes can be further simplified as follows:\n\n```java\n    public String getSmallestString(int n, int k) {\n        int z = (k - n - 1) / 25, r = (k - n - 1) % 25;\n        return "a".repeat(n - z - 1) + (char)(\'a\' + r + 1) + "z".repeat(z);\n    }\n```\n```python\n    def getSmallestString(self, n: int, k: int) -> str:\n        z, r = divmod(k - n, 25)\n        return \'a\' * (n - z - 1) + chr(ord(\'a\') + r) * (n > z) + \'z\' * z\n```\n**Analysis:**\nTime & space: O(n)\n
['Java', 'Python3']