C++ || O(N)
Connect with me on LinkedIn: https://www.linkedin.com/in/abhay5349singh/\n\nApproach:\n convert most significant chars within available moves to lowest char poo
**Connect with me on LinkedIn**: https://www.linkedin.com/in/abhay5349singh/\n\n**Approach:**\n* convert most significant chars within available moves to lowest char poosible\n* next_idx = (idx+cur_k)%26; => possible char after shifting in forward direction\n* prev_idx = (idx-cur_k+26)%26; => possible char after shifting in backward direction\n\n```\nclass Solution {\npublic:\n    string getSmallestString(string s, int k) {\n        int n=s.length();\n        \n        string ans="";\n        for(int i=0;i<n;i++){\n            int cur_k = min(k,25); // max number of moves required to transform char to [a,z] \n            int extra_moves = k-cur_k;\n            \n            if(k==0){\n                ans += s.substr(i);\n                break;\n            }\n            \n            char ch = s[i];\n            \n            // utilizing max moves possible to get minimum char for current position\n            int idx = ch-\'a\';\n            int next_idx = (idx+cur_k)%26; \n            int prev_idx = (idx-cur_k+26)%26;\n            \n            // check if it was possible to get \'a\' with less number of moves available \n            \n            int k1=cur_k;\n            if(next_idx > 0){\n                next_idx = 0;\n                k1 = 26-idx;\n            }\n            \n            int k2=cur_k;\n            if(prev_idx > idx){\n                prev_idx = 0;\n                k2 = idx;\n            }\n            \n            // assigning random char with ascii > z\n            char ch1=\'|\', ch2=\'|\';\n            \n            if(k1 <= cur_k) ch1 = (char)(next_idx+\'a\');\n            if(k2 <= cur_k) ch2 = (char)(prev_idx+\'a\');\n            \n            if(ch1 < ch2){\n                ans += ch1;\n                cur_k -= k1;\n            }else if(ch2 < ch1){\n                ans += ch2;\n                cur_k -= k2;\n            }else{\n                ans += ch1;\n                cur_k -= min(k1,k2);\n            }\n            \n            k = cur_k + extra_moves;\n        }\n        \n        return ans;\n    }\n};\n```\n\n**Do upvote if it helps :)**
[]