EASY || convert the opposite direction movements
Intuitionwhy where we end cannot be the maximum distance?manhatten distance = (x, y) = x+y from originduring the middle stages, you would have gone 4N, 2S, 1E,
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
**why where we end cannot be the maximum distance?**

manhatten distance = (x, y) = x+y from origin

during the middle stages, you would have gone 4N, 2S, 1E, 0W

since the x you cover and y you cover is to be maximized

**assume k = 2, then optimal is 4+2N, 0S, 1E, 0W (ans = 6N-0S+1E-0W = 7)**

now after some time in your journy you go 2S extra

current directions are: 4N, 4S, 1E, 0W
**the optimal is 4+2N, 2S, 1E, 0W (ans = 6N-2S + 1E-0W = 5)**

hence calculate the optimal arrangement at every instance

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

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

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

# Code
```cpp []
#define ll long long 

class Solution {
public:
    int maxDistance(string s, ll k) {
        map<char, ll>mp;
        ll n = s.size();
        ll ans = 0;
        for(int i = 0; i<n; i++){
            mp[s[i]]++;
            //manhattan distance = (x, y) !! maximize
            
            ll k1 = k;
            ll tmpans = 0;
            ll tmp1 = min(mp['N'], mp['S']);
            tmpans += max(mp['N'], mp['S']) + min(k1, tmp1);
            tmpans -= (tmp1 - min(k1, tmp1));  //opposite direction that was not changed 
            k1 -= min(k1, tmp1);

            ll tmp2 = min(mp['E'], mp['W']);
            tmpans += max(mp['E'], mp['W']) + min(k1, tmp2);
            tmpans -= (tmp2 - min(k1, tmp2));  //couldnt change this direction
            k1 -= min(k1, tmp2);

            //tmpans += k1;  //we cannot do more steps

            ans = max(ans, tmpans);           
        }

        return ans;
    }
};
```
['Greedy', 'C++']