Problem
A grid mat describes an army: 1 is a soldier and 0 is a civilian. In every row, all the soldiers stand before all the civilians (the 1s come first).
Row i is weaker than row j if it has fewer soldiers, or the same number of soldiers and i < j. Return the indices of the `k` weakest rows, weakest first.
Example 1
mat = [[1,1,0,0,0],
Example 2
[1,1,1,1,0],
Example 3
[1,0,0,0,0],
Example 4
[1,1,0,0,0],
Example 5
- Input
- [1,1,1,1,1]], k = 3
- Output
- [2, 0, 3]
Soldier counts are 2, 4, 1, 2, 5. Row 2 is weakest, then rows 0 and 3 (tied at 2, so the smaller index first).
Constraints
2 <= m, n <= 100 (m rows, n columns)1 <= k <= mmat[i][j] is 0 or 1.