Mini-Max Sum Solution in Kotlin -HackerRank

16 24
1 < arr[i] < 10
1 2 3 4 5
10 14
fun miniMaxSum(arr: Array<Int>): Unit {    var min:Long =  arr[0].toLong()
var max:Long = 0
var total:Long = 0
for (x in 0 until arr.size) {
val item = arr[x].toLong()
total += item
if (item < min) {
min = item
}
if (item > max) {
max = item
}
}
println("${total - max} ${total - min}")}
  1. If we sum everything except 2, our sum is 1+3+4+5 = 13.
  2. If we sum everything except 3, our sum is 1+2+4+5 = 12.
  3. If we sum everything except 4, our sum is 1+2+3+5 = 11.
  4. If we sum everything except 5, our sum is 1+2+3+4 = 10.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store