Greedy | C++ | python 
IntuitionThe Idea is that if things go as we expected then at every  position i we will have a manhattan distance equal to (i + 1) 0-indexed.ApproachIf we have
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The Idea is that if things go as we expected then at every  position i we will have a manhattan distance equal to (i + 1) 0-indexed. 

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

If we have s = "NS" and k = 1, then if 'S' were replaced with any other direction, the Manhattan distance would be 2. However, in its current state, the distance is 0.

By modifying one direction, we can increase the Manhattan distance to 2. More generally, if we have k positions to modify, we can gain k × 2 in Manhattan distance. The specific direction of modification doesn’t matter.

# 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
```python3 []
class Solution:
    def maxDistance(self, s: str, k: int) -> int:
        pos = {'N':[1, 0], 'S':[-1, 0], 'W':[0, 1], 'E':[0,-1]}
        start = [0,0]
        ans = 0
        for i, ch in enumerate(s):
            i += 1
            start[0] += pos[ch][0]
            start[1] += pos[ch][1]
            cur =  abs(start[0]) + abs(start[1])
            
           
            
            ans = max(ans, cur, min(i, cur + (k * 2)))
        return ans       
            
```

```C++ []
class Solution {
public:
    int maxDistance(string s, int k) {
        unordered_map<char, vector<int>> pos = {
            {'N', {1, 0}}, {'S', {-1, 0}}, {'W', {0, 1}}, {'E', {0, -1}}
        };

        vector<int> start = {0, 0};
        int ans = 0;

        for (int i = 0; i < s.size(); ++i) {
            start[0] += pos[s[i]][0];
            start[1] += pos[s[i]][1];

            int cur = abs(start[0]) + abs(start[1]);
            ans = max({ans, min(i + 1, cur + (k * 2))});
        }

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