Javascript | Simple Math | O(n)
Code
# Code
```javascript []
/**
 * @param {string} s
 * @param {number} k
 * @return {number}
 */
var maxDistance = function(s, k) {
    counter = new Map();
    counter.set('N', 0);
    counter.set('S', 0);
    counter.set('E', 0);
    counter.set('W', 0);
    let res = 0;
    for(let i = 0; i < s.length; i++){
        counter.set(s[i], counter.get(s[i])+1);
        let maxv = Math.max(counter.get('N'), counter.get('S'));
        let minv = Math.min(counter.get('N'), counter.get('S'));
        let maxh = Math.max(counter.get('E'), counter.get('W'));
        let minh = Math.min(counter.get('E'), counter.get('W'));
        res = Math.max(res, maxv+maxh+2*Math.min(k,minv+minh)-(minv+minh));
    }
    return res;
    
};
```
['JavaScript']