One pass math
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 st, int k) {
        int n=0,s=0,w=0,e=0;
        int mx=0,curr=0;
        for(char c:st){
            if(c == 'N')n++;
            if(c == 'E')e++;
            if(c == 'S')s++;
            if(c == 'W')w++;
            curr = abs(n-s)+abs(e-w);
            int z = k-min(k,(min(n,s)));
            mx=max(mx,curr+2*min(k,(min(n,s)))+2*min(z,min(e,w)));
        }
        return mx;
        
    }
};
```
['C++']