Created
April 25, 2024 10:27
-
-
Save JunJaBoy/1305f4d37e82572863ef25a16998bc28 to your computer and use it in GitHub Desktop.
HackerRank/Algorithm/CountingSort kotlin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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