BEAT 100% CPP Code
Intuition\n1. First take a string of same size of s as  "aaaa...n"\n2. Then traverse the string s if s[i]==t[i] continue\n3. Calculate the direct distance and r
# Intuition\n1. First take a string of same size of s as  "aaaa...n"\n2. Then traverse the string s if s[i]==t[i] continue\n3. Calculate the direct distance and reverse distance between "a" or t[i] and s[i] and take minimum of them.\n4. Check if this is smaller than k then we are unable to make "a" so we take character ((s[i]-\'a\'-k))+\'a\'.\n\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\nTime complexity: O(n)\n\n\n Space complexity: O(1) \n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    string getSmallestString(string s, int k) {\n        int n=s.size();\n        // let the smallest string of size n be "aaa....n"\n        string t="";\n        for(int i=0;i<n;i++){\n            t+=\'a\';\n        }\n        int i=0;\n        while(i<n && k>0){\n            if(s[i]==t[i]){\n                i++;\n                continue;\n            }\n            char ch=s[i];\n            char c=t[i];\n            int direct_dis=(ch-\'a\')- (c-\'a\');\n            int reverse_dis=26-(ch-\'a\')+(c-\'a\');\n            int dis=min(direct_dis,reverse_dis);\n            // minimum distance is also greater than k than we have to replace the char\n            if(k<dis){\n                // replacing the char in t[i]\n                t[i]=((ch-\'a\')-k)+\'a\';\n                // no k left\n                k=0;\n            }\n            else{\n                k-=dis;\n            }\n            i++;\n        }\n        // for testcase lol we have to again travere the s.\n        while(k==0 && i<n ){\n            t[i]=s[i];\n            i++;\n        }\n        return t;\n    }\n};\n```
['C++']