Solved LeetCode program · 967 of 1,000
#1337 · The K Weakest Rows in a Matrix
Original English source
The grid is a list of 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, and 1. The rows is 5, while the columns is 5, while the wanted is 3. Keep a shared strengths as an empty list of whole numbers. Keep a shared chosen as an empty list of whole numbers. Keep a shared best of 0. Keep a shared lowest of 0.
For every line from 0 to 4.
Place 0 into strengths. Place 0 into chosen.
For every line from 0 to 4.
The spot is line times 5.
Repeat while spot is less than (line plus 1) times 5 and item spot of grid is 1.
Increase item line of strengths by 1. Add 1 to spot.
To choose. Set best to -1. Set lowest to 1000000.
For every line from 0 to 4.
If item line of chosen is 0 and item line of strengths is less than lowest, set best to line, set lowest to item line of strengths.
For every pick from 1 to wanted.
Choose. Set item best of chosen to 1. Show best.
Expected stdout
2 0 3