Simple Understanding. 
IntuitionWe have to make some flips and check the maximum distance at every point.Approach
Keep track of directions count.
We can only Flip either N or S in (N
# Intuition
We have to make some flips and check the maximum distance at every point.
# Approach
1. Keep track of directions count.
2. We can only Flip either N or S in (N and S set) 
3. Or E or W in (E and W set) 
4. We have to Flip which are lesser in count in each set so add the smaller values in both sets . For example if we have N's - 3 , S's -2 , E's -4 , W's - 2 :- here the smallerCount will be 4 (2-S's in 1st set & 2-W's in 2nd set) Consider k = 5 
5. So if k > smallerCount then : we can flip all of them 
6. if k < smallerCount then : we can only flip k , as we flip 1 Direction it increases the total Distance by 2 .  So  |c1-c2| + |c3-c4|    ( normal distance without any changes) + 2*k 
                             (additional distance due to flipping k ) 


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

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

# Code
```java []
class Solution {
    public int maxDistance(String s, int k) {
        int c1 = 0, c2 = 0, c3 = 0, c4 = 0; // 1 - N , 2 - S , 3 - E , 4 - W
        int maxD = 0;

        for (char c : s.toCharArray()) {
            if (c == 'N') {
                c1++;
            } else if (c == 'S') {
                c2++;
            } else if (c == 'E') {
                c3++;
            } else {
                c4++;
            }
            int minSum = 0;
            minSum = (c1 < c2 ? c1 : c2);
            minSum += (c3 < c4 ? c3 : c4);
            if (minSum < k) { // see 5. in Approach
                maxD = Math.max(maxD, c1 + c2 + c3 + c4);
            } else { // // see 6. in Approach
                maxD = Math.max(maxD, (Math.abs(c1 - c2) + Math.abs(c3 - c4) + 2 * k));
            }
        }
        return maxD;

    }
}

```
['Hash Table', 'Math', 'String', 'Counting', 'Java']