# The K Weakest Rows In A Matrix: Walkthrough
The K Weakest Rows In A Matrix shows up often in coding rounds. Here is how I talk through it when the interviewer is watching.
## Key idea
The strength of a row is the count of leading 1s (binary-search the first 0). Push (strength, index) into a max-heap of size k so the heap keeps the k weakest rows, then sort those k by the same key.
## Steps to say out loud
1. Restate the input and the exact ask, and nail down constraints and overflow.
2. Name the pattern (a heap or priority queue, Union-Find, interval scheduling, bitmask DP, a topological order, or a Trie) and why a nested scan or naive search fails.
3. Code it, then trace a short example plus one empty or already-solved edge case.
## Complexity
O(m log n + m log k).
## Common mistake
Scanning every cell to count 1s and then sorting all m rows when k is much smaller than m.
## Practice tip
Time yourself: two minutes to explain, ten to code, three to test edges. Disclosure: I work on Linkjob AI. I also keep a practice cheat sheet at the Linkjob AI app.