Menu
Coddy logo textTech

Challenge - Score Audit

Part of the Logic & Flow section of Coddy's Kotlin journey. Lesson 62 of 63.

challenge icon

Challenge

Expert

Complete scoreAudit with parameters rows: List<String>. Each row is name:score. Ignore rows unless splitting on : produces exactly two fields, the trimmed name matches [a-z]+, and the trimmed score parses as Int from 0 through 100. For repeated names, keep the latest valid score; invalid rows never replace earlier scores. Return name=score entries by decreasing score, breaking ties alphabetically.

Unless stricter bounds are stated above, collections contain at most 100 elements at each level, and integer arguments and integer collection values are between -1000 and 1000. Text supplied for parsing can include invalid or out-of-range representations as described.

Return a value of type List<String>. Keep the supplied input/output code. It reads scalar arguments one per line; a list starts with its count followed by its elements, and a map starts with its entry count followed by each key and value. Nested lists repeat the count-and-elements format for each row. The supplied main prints the return value followed by one newline. Lists use Kotlin's standard bracketed format; print no additional labels.

Try it yourself

fun scoreAudit(rows: List<String>): List<String> {
    // Write your solution here.
    return emptyList()
}
fun main() {
    val rowsCount = readln().toInt()
    val rows = mutableListOf<String>()
    for (i0 in 0 until rowsCount) {
        val rowsItem = readLine().orEmpty()
        rows.add(rowsItem)
    }
    println(scoreAudit(rows))
}

All lessons in Logic & Flow

Practice on your own: Kotlin playground