| Task: | Traffic jam |
| Sender: | aalto26am_022 |
| Submission time: | 2026-08-31 17:36:56 +0300 |
| Language: | Scala |
| Status: | COMPILE ERROR |
Compiler report
input/TrafficJam.scala:20: error: 'while' expected but 'val' found.
val count = times.groupBy(identity).mapValues(_.size).maxBy(_._2)._2
^
input/TrafficJam.scala:21: error: '(' expected but ';' found.
println(count)
^
two errors foundCode
import scala.io.StdIn.readLine
object TrafficJam {
def main(args: Array[String]): Unit = {
val numCars = readLine().toInt
var i = 0
var times: List[Int] = List()
while (i < numCars) do {
val Array(a,b) = readLine.split(" ").map(_.toInt)
for (t <- a to b){
times = times :+ t
}
i += 1
}
val count = times.groupBy(identity).mapValues(_.size).maxBy(_._2)._2
println(count)
}
}
