HackerRank Equal with Scala
The performance issue and the bug

The program essentially looks for the minimum operations to reduce the numbers to some base line.
There are two problems with the choice of base lines.

The performance issue is that you try base lines from 0 until the minimum value.
Consider this input:

999


The program will check base lines from 0 to 999, in vain.
You need up check only the 3 baselines: min, min - 1 and min - 2.

The second problem is a bug, and it is a related issue.
Consider this input:

0 4 4


The program will check only one base line, 0.
And that will give the incorrect result 4.
Checking -1 would give the correct result 3.

Working with user input

The readInt method is deprecated in favor of StdIn.readInt.

The way you parsed the input is unnecessarily complicated.
This line is commented out,
even though it was really on the right track:


val numbers = scala.io.StdIn.readLine().split(" ").map(s =&gt; s.toInt);



Scala style

Some of the var could have been val or unnecessary altogether,
and semicolons at end of lines are not recommended.
Also, you used Range(0, numOfTestCases) at one point,
even though you used the more idiomatic x.until(y) syntax elsewhere.

Alternative implementation

Putting the above tips together:

import scala.io.StdIn

object Solution {

  def main(args: Array[String]): Unit = {
    val numOfTestCases = StdIn.readInt()
    0.until(numOfTestCases).foreach(_ =&gt; {
      StdIn.readInt()
      val numbers = StdIn.readLine().split(" ").map(s =&gt; s.toInt)
      println(calOpCount(numbers))
    })
  }

  def steps(i: Int): Int = {
    if (i == 0) 0
    else if (i == 1 || i == 2 || i == 5) 1
    else i / 5 + (i % 5) / 2 + ((i % 5) % 2)
  }

  def calOpCount(source: Array[Int]): Int = {
    val min = source.min
    (for {base &lt;- 0.to(2)} yield source.map(s =&gt; steps(s - min + base)).sum).min
  }
}