scala oneliner
```scala []
object Solution {
  def maxDistance(s: String, k: Int): Int =
    Iterator("NE", "NW", "SE", "SW").map{dirs =>
      s.scanLeft((0,k)){case ((dist,rem),dir) =>
        if(dirs.contains(dir)) (dist+1,rem)
        else (dist+rem.sign*2-1,rem-rem.sign)
      }.map(_._1).max
    }.max

  // more verbose
  def maxDistance0(s: String, k: Int): Int =
    Iterator("NE", "NW", "SE", "SW").map{dirs =>
      s.scanLeft((0,k)){case ((dist,rem),dir) =>
        if(dirs.contains(dir)) (dist+1,rem)
        else if(rem>0) (dist+1,rem-1)
        else (dist-1,rem)
      }.map(_._1).max
    }.max
}
```
['Scala']