Skip to content

Instantly share code, notes, and snippets.

@JunJaBoy
Created April 25, 2024 10:27
Show Gist options
  • Save JunJaBoy/1305f4d37e82572863ef25a16998bc28 to your computer and use it in GitHub Desktop.
Save JunJaBoy/1305f4d37e82572863ef25a16998bc28 to your computer and use it in GitHub Desktop.
HackerRank/Algorithm/CountingSort kotlin
fun countingSort(arr: Array<Int>): Array<Int> =
IntArray(100) { 0 }
.apply {
arr.forEach { this[it]++ }
}
.toTypedArray()
fun main(args: Array<String>) {
val n = readln().trim().toInt()
val arr = readln().trimEnd()
.split(" ")
.map(String::toInt)
.toTypedArray()
val result = countingSort(arr)
println(result.joinToString(" "))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment