Shortest and simplest solution C++
IntuitionAt each point we see how much is the currDis and by how much could we increase it if we had not made mistakes( here taking the opposite directions) lik
# Intuition
At each point we see how much is the currDis and by how much could we increase it if we had not made mistakes( here taking the opposite directions) like if we are North of origin and in the path till now if we have made any South, then if we could correct that out currDis would be dis+2 .

# Approach
We just count the number of mistake we have made and take max of number of corrections we have and total mistakes at each point in the path.

# Complexity
- Time complexity:
O(n)

- Space complexity:
O(n)

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