Best solution | C++ | Smallest string
IntuitionWe need to construct a lexicographically smallest string t such that the cyclic distance between s and t is at most k. This approach ensures that we ob
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
We need to construct a lexicographically smallest string t such that the cyclic distance between s and t is at most k. This approach ensures that we obtain the smallest lexicographical string while keeping the distance constraint satisfied.
# Approach
<!-- Describe your approach to solving the problem. -->
The cyclic distance between two characters s[i] and t[i] is given by:
min(∣s[i]−t[i]∣,26−∣s[i]−t[i]∣)
Since we want t to be lexicographically smallest, we try to change each character in s to 'a' first, as 'a' is the smallest letter.

# Algorithm
Traverse s from left to right.
For each character s[i], check how much it costs to change it to 'a'.
The cost is min(|s[i] - 'a'|, 26 - |s[i] - 'a'|).
If we can afford to change s[i] to 'a' (i.e., cost ≤ k), we do it and subtract the cost from k.
Otherwise, we decrement s[i] lexicographically as much as possible within the remaining k.
Stop when k == 0 or after processing the entire string.


# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    string getSmallestString(string s, int k) {
        int n = s.size();
        for (int i = 0; i < n; i++) {
            int costToA = min(s[i] - 'a', 26 - (s[i] - 'a')); 
            if (k >= costToA) {  
                s[i] = 'a';  
                k -= costToA; 
            } else {  
                s[i] = s[i] - k;  
                k = 0;
                break;
            }
        }
        return s;
    }
};

```
['C++']