You’re given an m × n binary matrix mat where each row has all 1s (soldiers) to the left of all 0s (civilians).
Row i is weaker than row j if:
it has fewer soldiers, or
they have the same number of soldiers and i < j.
Return the indices of the k weakest rows, ordered from weakest to strongest.
Input: mat = [ [1,1,0,0,0], [1,1,1,1,0], [1,0,0,0,0], [1,1,0,0,0], [1,1,1,1,1] ], k = 3
Output: [2,0,3]
Explanation:
Soldiers per row: [2,4,1,2,5] Order: [2,0,3,1,4] → first 3 = [2,0,3].
Input: mat = [ [1,0,0,0], [1,1,1,1], [1,0,0,0], [1,0,0,0] ], k = 2
Output: [0,2]
Explanation:
Soldiers per row: [1,4,1,1] Order: [0,2,3,1] → first 2 = [0,2].
Accepted:
Submission: