Simple Math: Calculate the no of pairs of opposite directions we can make and use K to flip them
IntuitionApproachComplexity
Time complexity:

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

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

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

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

# Code
```python3 []
class Solution:
    def maxDistance(self, s: str, k: int) -> int:
        
        counter = defaultdict(int)
        
        maxDist = 0
        for cha in s:
            counter[cha] += 1
            NSmin = min(counter["N"], counter["S"]) #North South Pairs
            EWmin = min(counter["E"], counter["W"]) #East West Pairs

            NSmax = max(counter["N"], counter["S"])
            EWmax = max(counter["E"], counter["W"])

            maxDist = max(maxDist, NSmax + EWmax - NSmin - EWmin + 2*min(k, NSmin + EWmin) )
        return maxDist
```
['Python3']