https://leetcode.com/problems/the-k-weakest-rows-in-a-matrix/description/ Easy

Решение

class Solution {
    fun kWeakestRows(mat: Array<IntArray>, k: Int): IntArray {
        val strength = mat.mapIndexed { index, row ->
            val soldiers = row.count { it == 1 }
            Pair(soldiers, index)
        }
        return strength.sortedWith(compareBy({ it.first }, { it.second }))
            .take(k)
            .map { it.second }
            .toIntArray()
    }
}