Skip to content

Instantly share code, notes, and snippets.

@cg4jins
Created July 4, 2019 15:45
Show Gist options
  • Save cg4jins/65fcc11a263c4033ed15c2770385bbc4 to your computer and use it in GitHub Desktop.
Save cg4jins/65fcc11a263c4033ed15c2770385bbc4 to your computer and use it in GitHub Desktop.
class Solution {
fun solution(N: Int, stages: IntArray): IntArray {
var stageCountMap = mutableMapOf<Int, Int>()
var failRateMap = mutableMapOf<Int, Float>()
var remained = stages.size
for (stage in stages){
if (stageCountMap.keys.contains(stage)){
val value = stageCountMap[stage]
stageCountMap[stage] = (value!! + 1)
}else{
stageCountMap[stage] = 1
}
}
for (stage in 1 .. N){
val count = stageCountMap[stage] ?: 0
var failRate: Float = (count.toFloat() / remained)
failRateMap[stage] = failRate
remained -= count
}
return failRateMap.toList().sortedByDescending { (key, value) -> value }.asSequence().map { it.first }.toList().toIntArray()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment