The numeric value of a lowercase character is defined as its position (1-indexed) in the alphabet, so the numeric value of a is 1, the numeric value of b is 2, the numeric value of c is 3, and so on.

The numeric value of a string consisting of lowercase characters is defined as the sum of its characters' numeric values. For example, the numeric value of the string "abe" is equal to 1 + 2 + 5 = 8.

You are given two integers n and k. Return the lexicographically smallest string with length equal to n and numeric value equal to k.

Note that a string x is lexicographically smaller than string y if x comes before y in dictionary order, that is, either x is a prefix of y, or if i is the first position such that x[i] != y[i], then x[i] comes before y[i] in alphabetic order.

&nbsp;
Example 1:

Input: n = 3, k = 27
Output: "aay"
Explanation: The numeric value of the string is 1 + 1 + 25 = 27, and it is the smallest string with such a value and length equal to 3.


Example 2:

Input: n = 5, k = 73
Output: "aaszz"


&nbsp;
Constraints:


	1 &lt;= n &lt;= 105
	n &lt;= k &lt;= 26 * n


class Solution:
    def getSmallestString(self, n: int, k: int) -> str:
        ans = ['a']*n # Initialize the answer to be 'aaa'.. length n
        val = n #Value would be length as all are 'a'

        for i in range(n-1, -1, -1):
            if val == k: # if value has reached k, we have created our lexicographically smallest string
                break
            val -= 1 # reduce value by one as we are removing 'a' and replacing by a suitable character
            ans[i] = chr(96 + min(k - val, 26)) # replace with a character which is k - value or 'z'
            val += ord(ans[i]) - 96 # add the value of newly appended character to value

        return ''.join(ans) # return the ans string in the by concatenating the list
class Solution {
    public String getSmallestString(int n, int k) {
        char[] ch = new char[n];
        for(int i=0;i<n;i++) {
            ch[i]='a';
            k--;
        }
        int currChar=0;
        while(k>0) {
            currChar=Math.min(25,k);
            ch[--n]+=currChar;
            k-=currChar;
        }
        return String.valueOf(ch);
    }
}
class Solution {
public:
    string getSmallestString(int n, int k) {
        string str="";
        for(int i=0;i<n;i++){
            str+='a';
        }
        int curr=n;
        int diff=k-curr;
        if(diff==0) return str;
        for(int i=n-1;i>=0 && diff>0;i--){
            if(diff>25){
                str[i]='z';
                diff-=25;
            }else{
                str[i]=char('a'+diff);
                return str;
            }
        }
        return str;
    }
};
// a a a a a
// 5
// diff= 73-5
// 
var getSmallestString = function(n, k) {
    k -= n
    let alpha ='_bcdefghijklmnopqrstuvwxy_',
        ans = 'z'.repeat(~~(k / 25))
    if (k % 25) ans = alpha[k % 25] + ans
    return ans.padStart(n, 'a')
};
Smallest String With A Given Numeric Value