Brute Force
Code


# Code
```cpp []
class Solution {
public:
    vector<string> v = {"NW", "WS", "SE", "NE"};
    int maxDistance(string s, int k) {
        int k_ = k;
        int ans = INT_MIN;
        for (auto i : v) {
            string s1 = s;
            for (char& ch : s1) {
                if (i[0] != ch && i[1] != ch) {
                    if (k > 0) {
                    ch = i[0];
                    k--;
                    }
                }
            }
            int cnt = 0;
            int mx = INT_MIN;
            for (char ch : s1) {
                if (i[0] == ch || i[1] == ch) cnt++;
                else cnt--;
                mx = max (mx , cnt);
            }
            ans = max (mx , ans);
            k = k_;
        }
        return ans;
    }
};



```
![Screenshot 2025-01-30 204758.png](https://assets.leetcode.com/users/images/45b1da01-f86d-4872-bb55-45db4b4323b9_1738501260.4328313.png)
['Greedy', 'C++']