spark DF multiple Iterations on Rows
Since each row is independent, then I think it is easier to iterate within the mapping function of each row until you get the final result, so that you don't have to iterate over the whole df multiple times.
import spark.implicits._

val data = Seq(
        (1, 2, 3, 4, 3),
        (6, 7, 8, 1, 2),
        (2, 4, 6, 8, 5)
      )

val columns = List("col1", "col2", "col3", "col4", "col5")
val arrayDf = spark.sparkContext.parallelize(data).map(row =>  {
    var plates: List[Int] = row.productIterator.toList.map {case i: Int => i}
    var store: Int = plates.last // Assuming last column is the store 
    plates = plates.dropRight(1) // remove the store column
    (0 until store).toList.foreach(i => {
        val min = plates.min
        val index = plates.indexOf(min)
        store -=1
        plates = plates.updated(index, min + 1)
    })
    plates :+ store // Add the store at the end (which is always 0) 
}).toDF(Seq("result"): _*)

// Convert the list of result into columns again
val df = arrayDf.select(columns.zipWithIndex.map{case (name, idx) => arrayDf("result")(idx).alias(name)}: _*)

df.show()

+----+----+----+----+----+
|col1|col2|col3|col4|col5|
+----+----+----+----+----+
|   3|   3|   3|   4|   0|
|   6|   7|   8|   3|   0|
|   6|   5|   6|   8|   0|
+----+----+----+----+----+


From the below data- col5 is holding the no of fruits to be distributed among plates from col1 to col4(4plates). Each time find the min from the plates(col1 to col4) add 1 fruit and reduce the fruit from col5 and repeat this process till col5(fruits becomes zero). Below is some sample code to find the min and add 1 fruit there. but how to do this recursively in spark - Scala.
Expected output:

  plate1 plate2 plate3  plate4  fruits  
  1 2   3   4   3   
  6 7   8   1   2   
  2 4   6   8   5   

Iteration 1:
  2 2   3   4   2   
  6 7   8   2   1   
  3 4   6   8   4   

Iteration 2:
  3 2   3   4   1   (If 2 plates has the same min value , left precedence)
  6 7   8   3   0   
  4 4   6   8   3   

Iteration 3:
  3 3   3   4   0   
  6 7   8   3   0   
  5 4   6   8   2   

Iteration 4:
  3 3   3   4   0   
  6 7   8   3   0   
  5 5   6   8   1   

Iteration 5:
  3 3   3   4   0   
  6 7   8   3   0   
  6 5   6   8   0   

code for first iteration:
      val data = Seq(
        (1.0, 2.0, 3.0, 4.0, 3.0),
        (6.0, 7.0, 8.0, 1.0, 2.0),
        (2.0, 4.0, 6.0, 8.0, 5.0)
      )
      val columns = List("col1", "col2", "col3", "col4", "col5")
      val df = spark.createDataFrame(data).toDF(columns: _*)

      val updatedColumns = columns.map { colName =>
        functions.when(col(colName) === functions.least(columns.map(col): _*), col(colName) + 1).otherwise(col(colName)).alias(colName)
      }

      val updatedDF = df.select(updatedColumns: _*)
      updatedDF.show()

