C++ | Easy and Clean Code
Code
# Code
```cpp []
class Solution {
public:
    int maxDistance(string s, int k) {
        int n=s.size();
        vector<pair<char, char>> vp={{'N', 'E'}, {'N', 'W'}, {'S', 'E'}, {'S', 'W'}};
        int ans=0;

        for(auto &x: vp){
            char a=x.first, b=x.second;
            int temp=0, mx=0;
            int m=k;

            for(int i=0; i<n; i++){
                mx=max(temp, mx);
                if(s[i]=='N' || s[i]=='S'){
                    if(s[i]==a) temp++;
                    else{
                        if(m>0){
                            temp++;
                            m--;
                        }
                        else temp--;
                    }
                }
                else if(s[i]=='W' || s[i]=='E'){
                    if(s[i]==b) temp++;
                    else{
                        if(m>0){
                            temp++;
                            m--;
                        }
                        else temp--;
                    }
                }
            }

            mx=max(temp, mx);
            ans=max(ans, mx);
        }

        return ans;
    }
};
```
['Math', 'String', 'Counting', 'C++']