Simple solution don't need to calculate for all direction.
IntuitionWe simply count horizontal(like south and north) and vertical direction (like east and west) in variable, then we gready convert them which will give u
# Intuition
 We simply count horizontal(like south and north) and vertical direction (like east and west) in variable, then we gready convert them which will give us the most profit.we will do it for every i take the maximum from it. 
 example: "NWSE", k = 1
    i = 0 , NS = 1,EW=0; total = min(abs(1)+abs(0)+2*1,1); total=1
    i = 1 , NS = 1,EW=1; total = min(abs(1)+abs(1)+2*1,2); total=2
    i = 2 , NS = 0,EW=1; total = min(abs(0)+abs(1)+2*1,3); total=3
    i = 3 , NS = 0,EW=0; total = min(abs(0)+abs(0)+2*1,4); total=2

    for North direction we will do +1 in NS and for south we will do -1 in NS.
    for East direction we will do +1 in EW and for south we will do -1 in EW.
   after that we try to pick best for them so will do 2*k because we have already done negative  for south and west cummulative in above example suppose i =2 then our NS=0 ,EW =1 ,if we will convert either north or south then our NS give profit of two that's why we have done 2*k.

# Approach
 

# Complexity
- Time complexity:
    $$O(n)$$

- Space complexity:
   constant space $$O(1)$$

# Code
```cpp []
public:
    int maxDistance(string s, int k) {
        int n = s.size();
        int ans = 1;
        int NS=0,EW=0;
        for(int i=0;i<n;i++){
          if(s[i]=='N'){
              NS++;
          }else if(s[i]=='S'){
              NS--;
          }else if(s[i]=='E'){
              EW++;
          }else{
              EW--;
          }
         ans = max(ans , min(abs(NS)+abs(EW)+2*k,i+1));
        }
        return ans;
    }
};
```
['C++']