[Java/C++/Python] Easy and Concise
Code
# Code
```java []
class Solution {
    public int maxDistance(String s, int k) {
        int x = 0, y = 0, res = 0;
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (c == 'N') {
                y++;
            } else if (c == 'S') {
                y--;
            } else if (c == 'E') {
                x++;
            } else if (c == 'W') {
                x--;
            }
            int L = i + 1;
            int d = Math.abs(x) + Math.abs(y);
            int possible = Math.min(L, d + 2 * k);
            res = Math.max(res, possible);
        }
        return res;
    }
    }
```
``` C++ []
class Solution {
public:
    int maxDistance(string s, int k) {
        int x = 0, y = 0, res = 0;

        for (int i = 0; i < s.length(); i++) {
            char c = s[i];

            // Update coordinates based on direction
            if (c == 'N') {
                y++;
            } else if (c == 'S') {
                y--;
            } else if (c == 'E') {
                x++;
            } else if (c == 'W') {
                x--;
            }

            int L = i + 1;  // Total steps taken
            int d = abs(x) + abs(y);  // Manhattan distance
            int possible = min(L, d + 2 * k);  // Max possible distance

            res = max(res, possible);
        }
        
        return res;
    }
};
```
``` Python []
class Solution:
    def maxDistance(self, s: str, k: int) -> int:
        x, y, res = 0, 0, 0

        for i, c in enumerate(s):
            # Update coordinates based on direction
            if c == 'N':
                y += 1
            elif c == 'S':
                y -= 1
            elif c == 'E':
                x += 1
            elif c == 'W':
                x -= 1

            L = i + 1  # Total steps taken
            d = abs(x) + abs(y)  # Manhattan distance
            possible = min(L, d + 2 * k)  # Max possible distance

            res = max(res, possible)
        
        return res
```

['String', 'Java']