fun customSort(input: String): String {
val chars = input.toCharArray().sortedWith { a, b ->
when {
a.isDigit() && b.isLetter() -> -1 // Digits before letters
a.isLetter() && b.isDigit() -> 1 // Letters after digits
else -> a.compareTo(b)
}
}
return chars.joinToString("")
}
fun main() {
val input = "d25c4b3ea1"
val sortedInput = customSort(input)
println("Custom sorted string: $sortedInput")
}
/*
run:
Custom sorted string: 12345abcde
*/