[Scala] Bottom-up DP with pattern matching for understandability
\n  def maxTaxiEarnings(n: Int, rides: Array[Array[Int]]): Long = {\n    rides.sortInPlaceBy { case Array(_, end, _) => end }\n\n    val dp = Array.ofDim[Long](
```\n  def maxTaxiEarnings(n: Int, rides: Array[Array[Int]]): Long = {\n    rides.sortInPlaceBy { case Array(_, end, _) => end }\n\n    val dp = Array.ofDim[Long](n + 1)\n    var rideIdx = 0\n    (1 to n).foreach { i =>\n      while (rideIdx < rides.length && rides(rideIdx)(1) == i) {\n        val Array(start, end, tip) = rides(rideIdx)\n        dp(i) = math.max(dp(end), dp(start) + end - start + tip)\n        rideIdx += 1\n      }\n      dp(i) = math.max(dp(i), dp(i - 1))\n    }\n\n    dp.last\n  }\n```
['Dynamic Programming', 'Scala']