✅ Explained with Comments | Easy | 90% | O(n) | JS
\n/* \nIdea is to build the string from the end.\n1. We create an array (numericArr) to store string (1 indexed) corresponding to it\'s \nnumeric value as given
```\n/* \nIdea is to build the string from the end.\n1. We create an array (numericArr) to store string (1 indexed) corresponding to it\'s \nnumeric value as given i.e [undefined,a,b,c,......,z] \n\nNow we have to fill n places i.e  _ _ _ _ _ _ (Think it as fill in the blanks)\n\nWe will fill this from the end. The highest value last bank can have is "z" i.e 26 numeric value\nbut we also have to fill remaining n-1 blanks and minimum value they can have is "a" i.e 1 numeric\nvalue. So it is clear the we will have to subtract these n-1 min values to fill nth blank\nso our nth value will be k-(n-1). In below code n===i\n\n2. So we calculate nth blank value i.e val=k - (n-1)\n\n3. Now if value >=26 then we fill this blank with z i.e numericArr[26] and reduce k by 26\ni.e k=k-26\n\nelse our value is <26 so we pick the string as numericArr[val] and k=k-val\n\nIn both if else case in step 3 we update our final string as str = numericArr[index] + str; (see below code)\n*/\nvar getSmallestString = function (n, k) {\n\tlet numericArr = [],\n\t\tstr = \'\';\n\t// Step 1 to build string numeric array\n\tfor (let i = 1; i <= 26; i++) {\n\t\tnumericArr[i] = String.fromCharCode(96 + i);\n\t}\n\tfor (let i = n; i > 0; i--) {\n\t\t// Step 2: Find nth blanks value\n\t\tlet val = k - (i - 1);\n\t\t// Step 3\n\t\tif (val >= 26) {\n\t\t\tstr = numericArr[26] + str;\n\t\t\tk = k - 26;\n\t\t} else {\n\t\t\tstr = numericArr[val] + str;\n\t\t\tk = k - val;\n\t\t}\n\t}\n\treturn str;\n};\ngetSmallestString(3, 27);\n```
['JavaScript']