C++ Seriously faster and simpler than all other solutions
Thoughts\n\nWhile writing the code I was thinking about what makes fast code:\n- Solve as much as you can at compile time (not runtime)\n- Minimize branching\n 
# Thoughts\n\nWhile writing the code I was thinking about what makes fast code:\n- Solve as much as you can at compile time (not runtime)\n- Minimize branching\n  - maximize predictive branching\n- Minimize expensive computations\n\nThese points helped me craft the answer and I think it led to more intuitive code. The comments explain more below.\n\n# Code\n```cpp []\n#include<string>\n\nclass Solution {\npublic:\n    std::string getSmallestString(std::string s, int k) {\n        //No need to create a new string. s is already a copy we can return.\n        //No need to do lots of calculations at runtime. Just find the difference between\n        //s[i] and \'a\' and use that difference as an index into the shift_amount array\n        int shift_amount[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,12,11,10,9,8,7,6,5,4,3,2,1};\n        for (size_t i = 0; i < s.size(); i++) {\n            //int shift is the smallest number of characters we need to shift if we want to get to \'a\'\n            int shift = shift_amount[s[i] - \'a\'];\n            //Notice only one runtime conditional branch statement.\n            if (k >= shift) {\n                s[i] = \'a\';\n                k -= shift;\n            }\n            //if we do not have enough k left to shift to an \'a\',\n            //we can only walk back k amount (we no longer have enough k to wrap back to a)\n            else {\n                s[i] = s[i] - k;\n                //leave early since we ran out of k\n                return s;\n            }\n        }\n        return s;\n    }\n};\n```
['C++']