var 진짜 쓰기 싫었는데!
class Solution {
fun solution(N: Int, stages: IntArray): List<Int> {
var challengerCnt = stages.size
val keepCntByStage = (1..N).associateWith { stage ->
stages.count { it == stage }
}
return keepCntByStage.entries.map { (stage, peopleCnt) ->
val failRate = (0.0).takeIf { challengerCnt == 0 } ?: (peopleCnt / challengerCnt.toDouble())
challengerCnt -= peopleCnt
stage to failRate
}.sortedWith ( compareByDescending<Pair<Int, Double>> { it.second }.thenBy { it.first })
.map { it.first }
}
}