LeetCode solutions

1463. The K Weakest Rows in a Matrix

My accepted Python solution to LeetCode problem 1463, The K Weakest Rows in a Matrix, running in 0ms.

  • Difficulty: Easy
  • Python
  • Runtime 0ms
  • Memory 17.6MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 0ms, memory 17.6MB, accepted 2025-12-30.

python
class Solution:
    def kWeakestRows(self, mat: List[List[int]], k: int) -> List[int]:
        soldiers = [(sum(row), i) for i, row in enumerate(mat)]
        soldiers.sort()
        return [soldiers[i][1] for i in range(k)]

Source