object MatrixDuplicateFinder {
// Helper function to convert a row to a string for comparison
def rowToString(row: Array[Int]): String = row.mkString(",")
// Function to find repeated rows in the matrix
def findRepeatedRows(matrix: Array[Array[Int]]): Unit = {
val rowCount = scala.collection.mutable.Map[String, Int]()
matrix.foreach { row =>
val pattern = rowToString(row)
rowCount(pattern) = rowCount.getOrElse(pattern, 0) + 1
}
println("Repeated Rows:")
rowCount.filter(_._2 > 1).foreach { case (pattern, count) =>
println(s"Row: [$pattern] - Repeated $count times")
}
}
def main(args: Array[String]): Unit = {
val matrix = Array(
Array(1, 2, 3),
Array(4, 5, 6),
Array(1, 2, 3),
Array(7, 8, 9),
Array(4, 5, 6),
Array(0, 1, 2),
Array(4, 5, 6)
)
findRepeatedRows(matrix)
}
}
/*
run:
Repeated Rows:
Row: [4,5,6] - Repeated 3 times
Row: [1,2,3] - Repeated 2 times
*/