Greedy C++ 
ApproachTo maximize distance, we adjust the minimum of vertical and horizontal counts (minV, minH) by utilizing up to k adjustments. For vertical (maxV), we add

# Approach
To maximize distance, we adjust the minimum of vertical and horizontal counts (minV, minH) by utilizing up to k adjustments. For vertical (maxV), we add min(k, minV) to maximize the difference between north and south. For horizontal (maxH), after adjusting vertical distance, we apply the remaining k to the horizontal direction. 


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

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

# Code
```cpp []
class Solution {
public:
    int maxDistance(string s, int k) {
        int e = 0, w = 0, n = 0, d = 0;
        int ans = 0;
        for(auto &c: s) {
            if(c == 'E') e++;
            if(c == 'W') w++;
            if(c == 'N') n++;
            if(c == 'S') d++;

            int maxV = max(n, d), minV = min(n, d);
            int maxH = max(e, w), minH = min(e, w);
            
            maxV += min(k, minV);
            int kLeft = k - min(k, minV);
            minV -= min(k, minV);
            maxH += min(kLeft, minH);
            minH -= min(kLeft, minH);

            ans = max(ans, maxV - minV + maxH - minH);
        }
        return ans;
    }
};

```
['C++']