Easy C++ Solution
\n# Intuition\nTo find the smallest lexicographically string, we need to start from the beginning of the given string s and convert characters to \'a\' if it re
\n# Intuition\nTo find the smallest lexicographically string, we need to start from the beginning of the given string s and convert characters to \'a\' if it reduces the overall lexicographical value. We do this until we exhaust the available operations k.\n\n# Approach\n- We iterate through each character of the string s. For each character, we calculate the distance to \'a\' both forward and backward. \n- - We choose the minimum of these distances as the distance needed to convert the current character to \'a\'. If this distance is less than or equal to the remaining operations k, we update the character to \'a\' and reduce k by the chosen distance. Otherwise, we only perform the operation on this character and break out of the loop.\n\nComplexity\nTime complexity: \n- O(n), where \nn is the length of the string s. We iterate through each character once.\n- Space complexity: \nO(1). We are using only a constant amount of extra space.\n\n# Code\n```\nclass Solution {\npublic:\n    string getSmallestString(string s, int k) {\n       int n = s.size();\n\n        for (int i = 0; i < n; i++) {\n            // Calculate the distance to \'a\' from the current character\n            int distance_forward = s[i] - \'a\';\n            // Calculate the distance to \'a\' from the opposite end\n            int distance_backward = (\'z\' - s[i]) + 1;\n            // Choose the minimum of the two distances\n            int min_distance = min(distance_forward, distance_backward);\n\n            // If the minimum distance is less than or equal to remaining k\n            if (min_distance <= k) {\n                // Reduce k by the chosen distance\n                k -= min_distance;\n                // Set the current character to \'a\'\n                s[i] = \'a\';\n            } else {\n                // If the minimum distance is greater than remaining k\n                // Subtract k from the current character to make it the smallest possible character\n                s[i] = s[i] - k;\n                // Reset k to 0 as no more changes needed\n                k = 0;\n            }\n        }\n        return s;\n    }\n};\n```
['C++']