Most intuitive and easy to understand solution.
Code
# Code
```java []
// so basically what you can have done is that, you can consider all cases, and then you can observing all the cases you could have found the answer. You could have use pen and paper and have done that!
// and also can collect all the observations and could have done the problem. Put your brain into it manhh.
class Solution {
    public int maxDistance(String s, int k) {
        /* 
            So the combinations can be N&E, E&S, W&S and W&N to make it go as far away as possible and
        */
        int count =0;
        int temp =0;
        int rest = k;
        for (int i=0; i<s.length(); i++) {
            if (s.charAt(i) == 'N' || s.charAt(i) == 'E') {
                temp++;
            } else {
                if (rest>0) {
                    rest--;
                    temp++;
                    count = Math.max(temp, count);
                } else {
                    count = Math.max(temp, count);
                    temp += -1;
                }
            }
        }
        rest = k;
        count = Math.max(count, temp);
        System.out.println(count);
        temp =0;
        for (int i=0; i<s.length(); i++) {
            if (s.charAt(i) == 'E' || s.charAt(i) == 'S') {
                temp++;
            } else {
                if (rest>0) {
                    rest--;
                    temp++;
                    count = Math.max(temp, count);
                } else {
                    count = Math.max(temp, count);
                    temp += -1;
                }
            }
        }
        rest = k;
        count = Math.max(count, temp);
        System.out.println(count);
        temp =0;
        for (int i=0; i<s.length(); i++) {
            if (s.charAt(i) == 'W' || s.charAt(i) == 'S') {
                temp++;
            } else {
                if (rest>0) {
                    rest--;
                    temp++;
                    count = Math.max(temp, count);
                } else {
                    count = Math.max(temp, count);
                    temp += -1;
                }
            }
        }
        rest = k;
        count = Math.max(count, temp);
        System.out.println(count);
        temp =0;
        for (int i=0; i<s.length(); i++) {
            if (s.charAt(i) == 'W' || s.charAt(i) == 'N') {
                temp++;
            } else {
                if (rest>0) {
                    rest--;
                    temp++;
                    count = Math.max(temp, count);
                } else {
                    count = Math.max(temp, count);
                    temp += -1;
                }
            }
        }
        count = Math.max(count, temp);
        System.out.println(count);
        return count;
    }
}
```
['Java']