Skip to content

Instantly share code, notes, and snippets.

@JunJaBoy
Created April 25, 2024 01:14
Show Gist options
  • Save JunJaBoy/b47c96ff8e7f252f833b57fa2df0a6af to your computer and use it in GitHub Desktop.
Save JunJaBoy/b47c96ff8e7f252f833b57fa2df0a6af to your computer and use it in GitHub Desktop.
HackerRate/Algorithm/MiniMaxSum kotlin
fun miniMaxSum(arr: Array<Int>) {
val sorted = arr.map(Int::toLong).sorted()
println("${sorted.dropLast(1).sum()} ${sorted.drop(1).sum()}")
}
fun main(args: Array<String>) {
val arr = readln().trimEnd()
.split(" ")
.map { it.toInt() }
.toTypedArray()
miniMaxSum(arr)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment