| https://leetcode.com/problems/increasing-decreasing-string/description/ | Easy |
|---|
fun sortString(s: String): String {
// Частота символов
val count = IntArray(26)
for (c in s) {
count[c - 'a']++
}
val result = StringBuilder()
val total = s.length
while (result.length < total) {
// Прямой проход: от 'a' к 'z'
for (i in 0..25) {
if (count[i] > 0) {
result.append('a' + i)
count[i]--
}
}
// Обратный проход: от 'z' к 'a'
for (i in 25 downTo 0) {
if (count[i] > 0) {
result.append('a' + i)
count[i]--
}
}
}
return result.toString()
}