C++ best solution
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    int maxDistance(string s, int k) {
   int ans=0;
        int n=s.size();
        map<char,int> mp;
        for(int i=0;i<n;i++){
            mp[s[i]]++;
            int temp =min(i+1,abs(mp['N']-mp['S']) + abs(mp['E']-mp['W']) +2*k);
            ans=max(ans,temp);
        }
        return ans;
    }
};
```
['C++']