-1
fun diagonalDifference(arr: Array<Array<Int>>): Int {
var tamanho = arr.size - 1
var i = 0
var diagonal1 = 0
var diagonal2 = 0
for(i in 0 .. tamanho){
diagonal1 += arr[i][i]
diagonal2 += arr[i][tamanho - i]
}
return diagonal2.minus(diagonal1)
}
fun main(args: Array<String>) {
val n = readLine()!!.trim().toInt()
val arr = Array<Array<Int>>(n, { Array<Int>(n, { 0 }) })
for (i in 0 until n) {
arr[i] = readLine()!!.trimEnd().split(" ").map{ it.toInt() }.toTypedArray()
}
val result = diagonalDifference(arr)
println(result)
}
In this my solution in Hacker Rank is approved in 4 cases but rejected in 6. I no longer know what to change, I am beginner and would like a help if possible.
Set the challenge prefix and the values they expect your program to return to (the tests you should pass)
– Thyago Dias