Scala FP: 1 pass foldLeft no simulation
Code\n\nobject Solution {\n  def timeRequiredToBuy(tickets: Array[Int], k: Int): Int =\n    tickets.indices.foldLeft(0)((sum, n) => sum + tickets(n).min(if (n >
# Code\n```\nobject Solution {\n  def timeRequiredToBuy(tickets: Array[Int], k: Int): Int =\n    tickets.indices.foldLeft(0)((sum, n) => sum + tickets(n).min(if (n > k) tickets(k) - 1 else tickets(k)))\n}\n```
['Scala']