Menu
Coddy logo textTech

Challenge - Shared Supplies

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

challenge icon

Challenge

Expert

Complete sharedSupplies with parameters requests: List<String>, available: List<String>. Each request is a comma-separated list of required items. Trim fields, lowercase ASCII names, and discard empty fields. A request is fulfillable if all its distinct required items appear in available after the same trim-and-lowercase normalization. Empty requests are fulfillable. Return index=ready or index=missing:item1,item2 per request, with missing names distinct and sorted. Use zero-based indices. Availability is membership, not quantity.

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 sharedSupplies(requests: List<String>, available: List<String>): List<String> {
    // Write your solution here.
    return emptyList()
}
fun main() {
    val requestsCount = readln().toInt()
    val requests = mutableListOf<String>()
    for (i0 in 0 until requestsCount) {
        val requestsItem = readLine().orEmpty()
        requests.add(requestsItem)
    }
    val availableCount = readln().toInt()
    val available = mutableListOf<String>()
    for (i0 in 0 until availableCount) {
        val availableItem = readLine().orEmpty()
        available.add(availableItem)
    }
    println(sharedSupplies(requests, available))
}

All lessons in Logic & Flow

Practice on your own: Kotlin playground