SOLUTION WRITTEN AFTER TRYING EVERY WAY. EASY CPP.
Code
# Code
```cpp []
class Solution {
public:
    int maxDistance(string s, int k) 
    {
        int size = s.length();
        int north = 0 , south = 0 , east = 0 , west = 0;
        int ans = 0;
        for(int i = 0 ; i < size ; i++)
        {
            if(s[i] == 'N') north++;
            if(s[i] == 'S') south++;
            if(s[i] == 'E') east++;
            if(s[i] == 'W') west++;

            int maxi = max(north , south);
            int mini = min(north , south);
            int temp = k;
            int del = min(mini , temp);
            int res = maxi - mini + 2 * del;
            temp -= del;
            maxi = max(east , west);
            mini = min(east , west);
            
            if(temp > 0)
            {
                del = min(mini , temp);
                res += maxi - mini + 2 * del;
            }
            else
            {
                res += maxi - mini;
            }

            ans = max(ans , res);
        }

        return ans;
            
    }
};
```
['C++']