Quick and Concise solution C# O(N)
Complexity
Time complexity: O(N)

Space complexity: O(1)
Code

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

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

# Code
```csharp []
public class Solution {
    public int MaxDistance(string s, int k) {
        int x = 0;
        int y = 0;
        int x1 = 0;
        int y1 = 0;
        int res = 0;
        for(int i = 0; i < s.Length; i++)
        {
            switch(s[i])
            {
                case 'N':
                    x++;
                    break;
                case 'S':
                    x1++;
                    break;
                case 'E':
                    y++;
                    break;
                case 'W':
                    y1++;
                    break;
            }
            int target = Math.Min(Math.Min(x, x1) + Math.Min(y, y1), k) * 2 + Math.Abs(x - x1) + Math.Abs(y - y1);
            res = Math.Max(res, target);
        }
        return res;
    }
}
```
![89f26eaf70fa927a79d4793441425859.jpg](https://assets.leetcode.com/users/images/e272f682-b72e-4f73-92fe-46fe9615b39f_1739538471.3527327.jpeg)

['Math', 'C#']