Greedy Approach (O(n) Time Complexity)
Approach1.Counting the Directional Moves:2.Handling Modifications (k Changes):3.Updating Maximum Distance:Complexity

Time complexity:
O(n) (single pass over st


# Approach
1.Counting the Directional Moves:

    Compute occurrences of N, S, E, W.
    The effective net displacement is determined by max(N, S) + max(E, W).

2.Handling Modifications (k Changes):

    The minimum possible moves (mini) represents canceling moves (min(N, S) + min(E, W)).
    If mini <= k, the mini is used to maximize distance.
    Otherwise, adjustments are made based on k.

3.Updating Maximum Distance:

    Iterate through the string, update and track maxi.

# Complexity
- Time complexity:
$$O(n)$$ (single pass over string)

- Space complexity:
$$O(1)$$ (only a few integer variables)

# Code
```cpp []
class Solution {
public:
    int maxDistance(string s, int k) {
        int maxi=0,dist=0,mini=0;
        int n=0,e=0,w=0,S=0;
        for(char c:s){
            if(c=='N')n++;
            if(c=='E')e++;
            if(c=='W')w++;
            if(c=='S')S++;
            dist=max(n,S)+max(e,w);
            mini=min(n,S)+min(e,w);
            if(mini<=k){
                dist+=mini;
            }else{
                dist+=k;
                dist-=(mini-k);
            }
            maxi=max(maxi,dist);
        }return maxi;
    }
};
```
['C++']