C++ | Greedy
Code

# Code
```cpp []
class Solution {
public:
    int maxDistance(string s, int k) 
    {
        map<char,int>m;
        int res=0;
        for(auto &c:s)
        {
            m[c]++;
            int hmx=max(m['E'],m['W']);
            int hmn=min(m['E'],m['W']);
            int conv=min(k,hmn);
            int curr=hmx-hmn+2*conv;
            int vmx=max(m['N'],m['S']);
            int vmn=min(m['N'],m['S']);
            conv=min(k-conv,vmn);
            curr+=(vmx-vmn+2*conv);
            res=max(res,curr);
        }
        return res;
    }
};
```
['C++']