Simple Basic C++ Soln. Only Loop
Intuition\nWe need the smallest string therefore I followed these simple steps to get my ans\n1--> add \'a\' till possible \n2--> add a char \n3--> now add \'z\
# Intuition\nWe need the smallest string therefore I followed these simple steps to get my ans\n1--> add \'a\' till possible \n2--> add a char \n3--> now add \'z\'\n\n# Approach\nNow the question arrises add \'a\' but till when . \nwe will use a number for example let n=3 and k=30.\n1--> add \'a\' then n=2 and k=29\n2--> add \'a\' again then n=1 and k=28 which is not possible bcoz last char is \'z\' with number 26.\n2--> we need to add 29-26=3 this is \'c\'\n3--> now add \'z\' \n\nWhich implies you can add \'a\' till your k is less than equal to(n-1)*26 .\nadd \'a\' till       \n\n    k <= (n-1)*26\n    k-(n-1)*26 <= 0\n\nnow if it is not possible then add char with value\n\n    k-(n-2)*26 \n\nbcoz you would need to n-2 \'z\' after this \n\nn is continuosly changing is this\n\nDo a dry Run for k=30,n=3 and any k=27,n=3 to understand it better.\n# Complexity\n- Time complexity:\nO(n) : where n is charater is output string\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\npublic:\n    string getSmallestString(int n, int k) {\n        string ans;\n        while(n!=0){\n            int ch = k-(n-1)*26;\n            if(ch<=0){\n                ans.push_back(\'a\');\n                k--;\n                n--;\n            }\n            else{\n                ans.push_back(ch+\'a\'-1);\n                n--;\n                k -= (ch);\n            }\n        }\n        return ans;\n    }\n};\n```
['C++']