[C++] Simple O(N) Solution | Brute Force Solution | 2 Solutions
\nclass Solution\n{\npublic:\n    // Best Solution\n    string getSmallestString(int n, int k)\n    {\n        string res(n, \'a\');\n        k -= n;\n        i
```\nclass Solution\n{\npublic:\n    // Best Solution\n    string getSmallestString(int n, int k)\n    {\n        string res(n, \'a\');\n        k -= n;\n        int midChar = 0;\n        while (k > 0)\n        {\n            midChar = min(k, 25);\n            k -= midChar;\n            res[n - 1] += midChar;\n            n--;\n        }\n        return res;\n    }\n};\n```\n\n\n```\nclass Solution\n{\npublic:\n    // Brute Force\n    string getSmallestString(int n, int k)\n    {\n        char al[] = {\'\\n\', \'a\', \'b\', \'c\', \'d\', \'e\', \'f\', \'g\', \'h\', \'i\', \'j\', \'k\', \'l\', \'m\', \'n\', \'o\', \'p\', \'q\', \'r\', \'s\', \'t\', \'u\', \'v\', \'w\', \'x\', \'y\', \'z\'};\n        string res = "";\n        int mid = 0;\n        do\n        {\n            if (k > 26)\n            {\n                if (k - 26 >= n - 1)\n                {\n                    res += al[26];\n                    k -= 26;\n                }\n                else\n                {\n                    mid = k - n + 1;\n                    res += al[mid];\n                    k -= mid;\n                }\n            }\n            else if (k != n)\n            {\n                mid = k - n + 1;\n                res += al[mid];\n                k -= mid;\n            }\n            else if (k == n)\n            {\n                res += al[1];\n                k -= 1;\n            }\n            n--;\n        } while (n > 0);\n        reverse(res.begin(), res.end());\n        return res;\n    }\n};\n```
[]