Simple For loop solution in C++
IntuitionApproachComplexity
Time complexity:
O(n)

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

# 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 s, int k) {
        int E=0,W=0,S=0,N=0;
        int ans=0;

        int n = s.size();

        for(int i=0;i<n;i++){
            if(s[i]=='E') E++;
            else if(s[i]=='W') W++;
            else if(s[i]=='S') S++;
            else N++;

            int temp = E+W+S+N;
            if(E>W) {
                if(S>N){
                    if(W+N>=k){
                        temp = (E+S+k) - (W+N-k);
                    }
                }else{
                    if(W+S>=k){
                        temp = (E+N+k) - (W+S-k); 
                    }
                }
            }else{
                if(S>N){
                    if(E+N>=k){
                        temp = (W+S+k) - (E+N-k);
                    }
                }else{
                    if(E+S>=k){
                        temp = (W+N+k) - (E+S-k);
                    }
                }
            }
            ans = max(ans, temp);
        }
        return ans;
    }
};
```
['C++']