✅ C++ || Dry Run || Easy || 🗓️ Daily LeetCoding Challenge || March || Day 22
Please Upvote If It Helps\n\nAlgorithm\n Initialise an string of length n with all \'a\'s\n\n Start traversing from the end of the string while k is positive\n 
**Please Upvote If It Helps**\n\n**Algorithm**\n* **Initialise** an string of length **n** with all **\'a\'s**\n\n* **Start traversing** from the **end of the string** while **k is positive**\n* add the element of the string by **\'z\' if k >= 25**\n* else add the **ascii value character** \n* At the same time decrease the **value of K** by **replaced element value**\n* Break the loop if **k==0**\n* return the final **result string** \n\n```\nclass Solution \n{\npublic:\n    string getSmallestString(int n, int k) \n    {\n        // declaring a string with size n with all values a \n        string res(n,\'a\');\n        \n        // substracting the n because we used the n times a in our string \n        k -= n;\n        \n        // make a while loop \n        // and iterate it till k gets 0\n        while(k>0)\n        {\n            // start changing the characters from behind for maintaining the  lexicographically smallest string \n            // take the min of (k,25) if its 25 the replace with z otherwise replace with Kth character\n            // and decraese that value from k\n            res[--n] += min(25,k);\n            k -= min(25,k);\n        }\n        return res;\n    }\n};\n```\n\n\n**Please Upvote If It Helps**\n// Dry Run \n// n = 4 , k = 37\n    \n//     res = "aaaa"\n//     k = (37-4) = 33\n    \n//     iteration 1.\n//     res[4] = min(25,33) = 25 = (\'a\'+25) = \'z\'\n//     k = (33-25) = 8\n//     4--\n    \n//     iteration 2.\n//     res[3] = min(25,8) = 8 = (\'a\'+8) = \'i\'\n//     k = (8-8) = 0\n//     3--\n    \n//     k == 0  (break the loop)
[]