Simple Soln beats 100% in O(N)
Intuitionsee we can go in two direction horizontal and vertical keep this in mind.
At every index check how much u can travel max and min in (n,s) direction and
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
see we can go in two direction horizontal and vertical keep this in mind.
At every index check how much u can travel max and min in (n,s) direction and same in (e,w) direction.
min distance will be in the opposite direction of max so it will lead to deduction of max distance from centre.
now see if we add the max distance of both direction and minimise the distance of both direction then we are the max distance from centre.
Now,how we can minimise the min distance?
see if sum of min distance is less than k that means min distance can be minimised to zero and be added to max distance
and if it ise greater than simply minus the k distance from min distance and add it to max distance

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

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

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

# Code
```cpp []
class Solution {
public:
    int maxDistance(string str, int k) {
        int ans=0;
        int n = 0;
        int w = 0;
        int s = 0;
        int e = 0;
        
        for(char c : str){
            if(c=='N'){
                n++;
            }else if(c=='W'){
                w++;
            }else if(c=='S'){
                s++;
            }else{
                e++;
            }
            int ma = max(n, s);
            int mi = min(n, s);
            int maa = max(w, e);
            int mii = min(w, e);
            int p = min(mi+mii, k);
            ans=max(ans,ma + maa -mi -mii + 2*p);
            
        }
        
        return ans;
        
    }
};
```
['C++']