Brute~Force C++
IntuitionApproach1 if u go left add+=1 and if u go right add-=12 similarly if u go up add+=1 and and if u go down add-=13 dist=abs(1+2)4 keep track of north,sou
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->
1 if u go left add+=1 and if u go right add-=1

2 similarly if u go up add+=1 and and if u go down add-=1

3 dist=abs(1+2)

4 keep track of north,south,west,east at each index

5 dist+=dist+=min(k,min(south,north))*2

6 k=k-min(k,min(south,north))

7 dist+=dist+=min(k,min(west,east))*2


# 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;
    int se=0;
    int w=0;
    int e=0;
        
    int d1=0;
    int d2=0;

    int ans=0;
        
    for(int i=0;i<s.size();i++){
        if(s[i]=='N'){
            n++;
            d1++;
        }
        
        else if(s[i]=='S'){
            se++;
            d1--;
        }
        
        else if(s[i]=='W'){
            d2++;
            w++;
        }
        else if(s[i]=='E'){
            d2--;
            e++;
        }

        int x=abs(d1);
        int y=abs(d2);

        int dist=x+y;
        int add=k;

        dist+=min(add,min(se,n))+min(add,min(se,n));
        add-=min(add,min(se,n));

        dist+=min(add,min(w,e))+min(add,min(w,e));

        ans=max(ans,dist);
    }
        
        
        
        
    return ans;
    
    }
};
```
['C++']