Check all the possible 8 directions :)
Code
# Code
```cpp []
class Solution {
public:
    int maxDistance(string s, int k) {
        int maxDist = 0;
        vector<unordered_set<char>> directions = {{'N', 'W'}, {'N'}, {'S'}, {'W', 'S'}, {'N', 'E'}, {'E', 'S'}, {'E'}, {'W'}};
        for(int i=0; i<directions.size(); i++){
            auto allowed = directions[i];
            int wrongs = 0, right = 0;
            for(int j=0; j<s.size(); j++){
                if(!allowed.count(s[j])) wrongs++; 
                if(allowed.count(s[j])) right++;
                int wrongsused = min(wrongs, k);
                maxDist = max(maxDist, right + wrongsused - max(0, wrongs - k));
            }
        }
        return maxDist;
    }
};
```
['C++']