Javascript | Recursive
Here we try to find out how many \'z\'s can be placed at the end of the desired output \n Let\'s say n = 3, k = 3; n <= k <= 78 -> All three places are required
Here we try to find out how many \'z\'s can be placed at the end of the desired output \n Let\'s say n = 3, k = 3; n <= k <= 78 -> All three places are required to be filled\n\n    3 -> aaa\n    4 -> aab\n    .\n    .\n    27 -> aay\n    28 -> aaz\n    29 -> abz\n    30 -> acz\n    \nSo, with n = 3, k = 3, lexicographically we can have aaa -> aaz strings.\nIn each iteration, we will try to find out a single character with its frequency which can be placed \nat the end of the string. \n    \n\tFor e.g n = 5, k = 82, output => "aczzz"\n\tIn first iteration, we will try to find out a char starting from z, then try out => y, x, w, .... c, b, a\n\tThen subtract z * 2 => 26 * 2 => 52.\n\tnewK = k - z * n(z) = 82 - 52 => 30\n\tnewN = k - n(z) = 5 - 2 = 3\nSo, if we trace it, then calls will be like \n    \n    \n                                                           getSmallestString(5, 82)\n                                                                     /\\\n                                                                    /  \\\n                                                                   /    \\\n                                                                  /      \\\n                                                                 /        \\\n                                                                /          \\\n                                            getSmallestString(3, 30)        "zz"\n                                                     /\\\n                                                    /  \\\n                                                   /    \\\n                                                  /      \\\n                                                 /        \\\n                                                /          \\   \n                              getSmallestString(2, 4)      "z"\n                                        /  \\\n                                       /    \\\n                                      /      \\\n                                     /        \\\n                                    /          \\   \n                  getSmallestString(1, 1)      "c" \n                            /  \\\n                           /    \\\n                          /      \\\n                         /        \\\n        getSmallestString(0, 0)   "a"\n                |\n                |\n                |\n                \u25BC\n                ""\n    \n    \n  Some, other examples: \n    \n\tn = 5, k = 5  => aaaaa\n    n = 5, k = 29 => aaaay\n    n = 5, k = 30 => aaaaz\n    n = 5, k = 31 => aaabz\n    n = 5, k = 55 => aaazz\n    n = 5, k = 56 => aabzz\n    \nLet\'s trace n = 5, k = 56:\t\n    \n                                                        getSmallestString(5, 56)\n                                                                     /\\\n                                                                    /  \\\n                                                                   /    \\\n                                                                  /      \\\n                                                                 /        \\\n                                                                /          \\\n                                            getSmallestString(4, 3)        "zz"\n                                                     /\\\n                                                    /  \\\n                                                   /    \\\n                                                  /      \\\n                                                 /        \\\n                                                /          \\   \n                              getSmallestString(2, 2)      "b"\n                                        /  \\\n                                       /    \\\n                                      /      \\\n                                     /        \\\n                                    /          \\   \n                  getSmallestString(1, 1)      "a" \n                            /  \\\n                           /    \\\n                          /      \\\n                         /        \\\n        getSmallestString(0, 0)   "a"\n                |\n                |\n                |\n                \u25BC\n                ""\n\n\n```\n/**\n * @param {number} n\n * @param {number} k\n * @return {string}\n */\n\nconst TO_ADD = 26 - 1;\n\nvar getSmallestString = function(n, k) {    \n    if (n <= 0 || k <= 0) {\n        return \'\';\n    }\n       \n    /* Refer comment#1 for this logic */\n    let highestCharFreq = Math.floor(k / (TO_ADD + n));\n    let i = 0;          \n    \n    while(highestCharFreq === 0 && i <= TO_ADD) {\n        i++;\n        highestCharFreq = Math.floor(k / (TO_ADD + n - i))        \n    }\n    \n    const highestCharCode = TO_ADD - i;\n    const highestChar = String.fromCharCode(97 + highestCharCode);\n    const newK = k - highestCharFreq * (highestCharCode + 1);\n    const newN = n - highestCharFreq;\n       \n    \n    \n    const output = `${getSmallestString(newN, newK)}${highestChar.repeat(highestCharFreq)}`;    \n    return output;\n};\n```\n\n
['JavaScript']