Beats 100% of users with c++ || O(26*N)❌O(N)✅
Intuition\nThe idea is to check if it\'s possible for result[i] to be \'a\'\n(for each index i)\n\n# Approach\nLet res be the result string (of same length)\n\n
# Intuition\nThe idea is to check if it\'s possible for result[i] to be \'a\'\n(for each index *i*)\n\n# Approach\nLet res be the result string (of same length)\n\n    For each index i:\n        if(distance(s[i],\'a\')<=k):  \n            res[i]=\'a\'\n            k-=distance(s[i],\'a\')<=k\n        else\n            res[i]=lexicographically least character at distance k\n            //s[i]-k\n            break\n    copy the remaining characters to the remaining integers\n\n# Complexity\n- Time complexity:\nO(N)\n\n- Space complexity:\nO(N) to store the result\n\n![sc.png](https://assets.leetcode.com/users/images/2a4dea9d-d8c7-4b42-ba5e-4dff2897d606_1712469191.09638.png)\n\n\n\n# Code\n```\nclass Solution {\npublic:\n    string getSmallestString(string s, int k) {\n        string res;\n        int i;\n        for(i=0;i<s.length();i++)\n        {\n            if((s[i]-\'a\')<=k||\'z\'-s[i]+1<=k)\n            {\n                res.push_back(\'a\');\n                k-=min(\'z\'-s[i]+1,s[i]-\'a\');\n            }\n            else\n            {\n                res.push_back(s[i]-k);\n                break;\n            }\n        }\n        for(int j=i+1;j<s.length();j++)\n        res.push_back(s[j]);\n        return res;\n    }\n};\n```\n\nPLEASE UPVOTE IF YOU FIND IT USEFUL\uD83E\uDD7A\uD83E\uDD7A\uD83E\uDD7A
['C++']