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