✔️ C++ concise solution | Explanation | minimum time and space complexity
Intuition:\nAs we have to create a lexicographically smallest string with a length of n. We have to place as many as the largest number back of the output strin
**Intuition:**\nAs we have to create ***a lexicographically smallest string with a length of n***. We have to place as many as the largest number back of the output string. To be more precise, for every iteration, our target is to place ***(i-1) a*** at the beginning, and for the last index, we just put the minimum number which remains from k.\n\n***Note:** During iteration, for any index, if we got the k is greater than 26, we just return 26 as we have only 26 characters possible. \n\n**Accepted Code:**\n```\nstring getSmallestString(int n, int k) {\n\n\tstring res(n, \' \');\n\n\tfor(int i=n; i>0; i--)\n\t{\n\t\tint charIdx = min(26, (k-i+1));\n\t\tres[i-1] = \'a\' + (charIdx - 1);\n\t\tk -= charIdx;\n\t}\n\n\treturn res;\n}\n```\n\n**Complexity:**\nTime Complexity: O(n)\nSpace Complexity: O(1) without considering the output string\n\n\n\n\n\n
['Greedy']