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
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 0ms, memory 17.6MB, accepted 2025-12-30.
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)]