1337. The K Weakest Rows in a Matrix

Updated: 2024-02-24
1 min read
[]

On This Page

LeetCode problem 1337

class Solution:
    def kWeakestRows(self, mat: List[List[int]], k: int) -> List[int]:
        m, n = len(mat), len(mat[0])
        res = [n - bisect_right(row[::-1], 0) for row in mat]
        idx = list(range(m))
        idx.sort(key=lambda i: res[i])
        return idx[:k]