scala solution
\n\ndef executeInstructions(n: Int, startPos: Array[Int], s: String): Array[Int] = {\n    def help(i: Int):Int ={\n      s.substring(i).foldLeft((startPos(0), s
```\n\ndef executeInstructions(n: Int, startPos: Array[Int], s: String): Array[Int] = {\n    def help(i: Int):Int ={\n      s.substring(i).foldLeft((startPos(0), startPos(1), 0))((acc, cur)=>{\n        cur match {\n          case \'L\' if acc._2 - 1 >= 0 => (acc._1, acc._2 - 1, acc._3 + 1)\n          case \'R\' if acc._2 + 1 < n  => (acc._1, acc._2 + 1, acc._3 + 1)\n          case \'U\' if acc._1 - 1 >= 0 => (acc._1 - 1, acc._2, acc._3 + 1)\n          case \'D\' if acc._1 + 1 < n  => (acc._1 + 1, acc._2, acc._3 + 1)\n          case _ => return acc._3\n        }\n      })._3\n    }\n    (0 until s.length).map(help(_)).toArray\n  }\n```
['Scala']