Easiest Explanation and beats 100%
IntuitionWe will traverse as per char in the string. We will calculate manhattan distance at each point. The max of manhattan distance will be our ans.ApproachW
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
We will traverse as per char in the string. We will calculate manhattan distance at each point. The max of manhattan distance will be our ans.

# Approach
<!-- Describe your approach to solving the problem. -->
We will maintain four variables, n,s,e,w, which will store the count of corresponding characters till now. We will use these to find the magnitude of coordinates at that point. Magnitude y coordinate is max(n,s)-min(n,s) and x cordinate is max(e,w)-min(e,w). Now we also have option to change k characters on the way , so we will change as many opposing charcaters that we can change i.e. min(min(n,s)+min(e,w),k). Each changing of characters will increase 2 units because currently we have gone 1 unit behind because of opposing character, but if we have changed at that point then we will be 1 unit front of that point. So we will calculate tempans for each coordinate i.e. tempans=  (max(n,s)-min(n,s))+( max(e,w)-min(e,w))+2*(min(min(n,s)+min(e,w),k)); And update our ans with max(ans,tempans) at each step.

# 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 []
class Solution {
public:
    int maxDistance(string S, int k) {
        int n=0,s=0,e=0,w=0;
        int ans=0;
        for(auto it:S){
            if(it=='N')n++;
            if(it=='S')s++;
            if(it=='W')w++;
            if(it=='E')e++;
            int maxy=max(n,s);
            int miny=min(n,s);
            int maxx=max(e,w);
            int minx=min(e,w);
            int tempans=(maxy-miny)+(maxx-minx)+2*(min((miny+minx),k));
            ans=max(ans,tempans);
        }
        return ans;
    }
};
```
['C++']