[scala] - Dijkstra, immutable, recursion
I am deeply concerned by the amount of attention given to Scala. Please upvote and submit your solutions.\n\n# Code\nscala []\nobject Solution {\n  import scala
I am deeply concerned by the amount of attention given to Scala. Please upvote and submit your solutions.\n\n# Code\n```scala []\nobject Solution {\n  import scala.collection.immutable.TreeSet\n\n  def minTimeToReach(moveTime: Array[Array[Int]]): Int = {\n    def inBorder(c: (Int, Int)) = c._1 >= 0 && c._1 < moveTime.length && c._2 >= 0 && c._2 < moveTime.head.length\n    def go(visited: Set[(Int, Int)], toVisit: TreeSet[(Int, Int, Int, Boolean)]): Int = {\n      val (cost, i, j, one) = toVisit.head\n      if (i == moveTime.length - 1 && j == moveTime.head.length - 1) cost\n      else {\n        val neighbours = neighbour4(i, j).filter(inBorder).filter(!visited.contains(_))\n        val next = neighbours.map(c => (math.max(cost, moveTime(c._1)(c._2)) + (if(one) 1 else 2), c._1, c._2, !one))\n        go(visited + ((i, j)), toVisit.tail ++ next)\n      }\n    }\n\n    go(Set((0, 0)), TreeSet((0, 0, 0, true)))\n  }\n\n  private def neighbour4(i: Int, j: Int): List[(Int, Int)] = List((i + 1, j), (i - 1, j), (i, j - 1), (i, j + 1))\n}\n```
['Scala']