1663 | C++ | Easy O(N) solution with explanation
Please upvote if you like this solution :)\n\nApproach:\n For getting smallest lexicographical order of string, Initially we define n size string and put \'a\'s
**Please upvote if you like this solution :)**\n\n**Approach:**\n* For getting smallest lexicographical order of string, Initially we define n size string and put \'a\'s into it.\n* Since string only contains \'a\'s we subtract n from k i.e. k=k-n;\n* Now, we traverse from the end of the string because we want smallest lexicographical order and that is only possible when we put large value characters at the end of the string.\n* We define 3 conditions for putting character in string these are....\ni) If k==0 break iteration.\nii) if k<25 then replace s[i] with (char)(\'a\'+k) and update k by k=0.\niii) and if k>25 then replace s[i] with (char)(\'a\'+25) and update k by k-25.\n* At the end return string\n\n**Time Complexity: O(N), Space Complexity: O(1)**\n\n**Code:**\n```\nclass Solution {\npublic:\n    string getSmallestString(int n, int k) \n    {\n        string s = "";\n        \n        //we put \'a\' in the nth size string to get smallest lexicographical order\n        for(int i=0; i<n; i++)\n            s += \'a\';\n    \n        k = k - n; //since we put \'a\'s in the string of size n\n        \n        //replace \'a\' from the end\n        for(int i=n-1; i>=0; i--)\n        {\n            if(k==0) break;\n            \n            else if(k<25)\n            {\n                s[i] = (char) (\'a\'+k); //use (char) for getting character of ASCII code\n                k=0;\n            }\n            else\n            {\n                s[i] = (char) (\'a\'+25);\n                k = k-25;\n            }\n        }\n        return s;\n        \n    }\n};\n```\n**Please upvote if you like this solution :)**
['Greedy', 'C']