python greedy
Code

# Code
```python3 []
class Solution:
    def maxDistance(self, s: str, k: int) -> int:
        d = {"N": (0, 1) , 'S': (0, -1), 'E':(1,0), 'W': (-1, 0)}
        r = rx = ry = 0
        for i in range(len(s)):
            x, y = d[s[i]]
            rx+=x
            ry+=y
            t = abs(rx) + abs(ry)
            r = max(r, t+ min(i +1 - t, 2* k))  
        return r 
                    
```
['Greedy', 'Python3']