very easy to understand, coded in c++;
Code
# Code
```cpp []
class Solution {
public:
    int maxDistance(string s1, int k) {
        int n = 0, s = 0, e = 0, w = 0;
        int ans = 0;
        for(int i = 0; i < s1.size(); ++i){
            if(s1[i]=='N') n++;
            else if(s1[i]=='S') s++;
            else if(s1[i]=='E') e++;
            else w++;
            int m = min(min(n,s)+min(e,w), k);
            ans = max(ans, abs(n-s)+abs(e-w)+2*m);            
        }
        return ans;
    }
};
```
['C++']