scala
scala \n  def getSmallestString(s: String, k: Int): String = {\n    @scala.annotation.tailrec\n    def f(ch: List[Char], remaining: Int, acc: List[Char]): List[
```scala \n  def getSmallestString(s: String, k: Int): String = {\n    @scala.annotation.tailrec\n    def f(ch: List[Char], remaining: Int, acc: List[Char]): List[Char] = ch match {\n      case Nil => acc.reverse\n      case head :: tail =>\n        val dis = (head - \'a\').min(\'z\' - head + 1)\n        if (dis > remaining) ((head - remaining).toChar :: acc).reverse ::: tail\n        else f(tail, remaining - dis, \'a\' :: acc)\n    }\n\n    f(s.toList, k, Nil).mkString\n  }\n```
['Scala']