Easy code with comments and key idea
\n// Key idea is to have as many "a"s at the beginning as possible, so that the \n// string will be lexicographically smallest.\n// Similarly, maximize "z"s at 
```\n// Key idea is to have as many "a"s at the beginning as possible, so that the \n// string will be lexicographically smallest.\n// Similarly, maximize "z"s at the end so that the character will be between \n// "a"s and "z"s will be as small as possible.\n// Say, n = 6 and k is 57, then we can\'t have more than 3 "a"s because 4 x "a"s\n// would mean remaining 2 characters should add up to (57-4) which is not possible.\n// So initial 3 characters are "aaa". Now we want to make 54 from 3 characters.\n// Because we want the first character to be as small as possible, it only makes sense\n// to have as many "z"s at the end as possible.\n// So although, "aaacyz" and "aaabzz" add to 57, "aaabzz" is the answer because it is\n// smaller of the two.\n\nclass Solution {\npublic:\n    string getSmallestString(int n, int k) {\n        string answer = "";\n        int a = n; // try to maximize "a"s at the beginning for \n                   // getting the lexicographically smallest string.\n        while ((k-a) > 26*(n-a)) {\n            a--;\n        }\n        // Now the variable `a` holds how many "a"s should be at the beginning.\n        k = k - a; \n        \n        int z = 0; // maximize "z"s at the end.\n        while (k >= (z+1)*26) {\n            z++;\n        }\n        // Now the variable `z` holds how many "z"s should be at the end.\n        \n        // Construct the answer now.\n        for (int i=0; i<a; i+=1) { // all "a"s at the beginning.\n            answer += "a";\n        }\n        if (a + z < n) { // if the string can not be made of only a and z, there \n                         // is a need of a character in between.\n            answer += (\'a\'+k-26*z-1);\n        }\n        for (int i=0; i<z; i+=1) { // all "z"s at the end.\n            answer += "z";\n        }\n        return answer;\n    }\n};\n```
[]