Submission details
Task:Traffic jam
Sender:aalto26am_022
Submission time:2026-08-31 17:25:30 +0300
Language:Scala
Status:COMPILE ERROR

Compiler report

input/TrafficJam.scala:10: error: '(' expected but identifier found.
    while i < numCars do {
          ^
input/TrafficJam.scala:20: error: illegal start of simple expression
    val count = times.groupBy(identity).mapValues(_.size).maxBy(_._2)._2
    ^
two errors found

Code

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)
  }
}