scala solution
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

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

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

# Code
```scala []
object Solution {
  val dir = Array(Array('N', 'E'), Array('N', 'W'), Array('S', 'E'), Array('S', 'W'))
  def maxDistance(s: String, k: Int): Int = dir.map { d =>
      s.foldLeft((0, k, 0)) { case ((curr, t, ans), char) =>
        if (char != d(0) && char != d(1)) {
          if (t > 0) (curr + 1, t - 1, Math.max(ans, curr + 1))
          else (curr - 1, t, Math.max(ans, curr - 1))
        } else (curr + 1, t, Math.max(ans, curr + 1))
      }._3
    }.max
}
```
['Scala']