Solved LeetCode program · 270 of 1,000
#0373 · Find K Pairs with Smallest Sums
Original English source
Keep a shared firsts holding 1, 7, and 11. Keep a shared seconds holding 2, 4, and 6. Keep a shared used as an empty list of whole numbers.
For every spot from 0 to 8.
Place 0 into used.
Keep a shared pickrow of 0. Keep a shared pickcolumn of 0. Keep a shared smallest of 0.
To scan from spot (a whole number). If spot is at least 9, return. The row is spot divided by 3. The column is spot modulo 3. The total is item row of firsts plus item column of seconds. If item spot of used is 0 and total is less than smallest, set smallest to total, set pickrow to row, set pickcolumn to column. Scan from spot plus 1.
The answers is an empty list of text. The round is 0.
Repeat while round is less than 3.
Set smallest to 1000000. Scan from 0. The slot is pickrow times 3 plus pickcolumn. Set item slot of used to 1. The chosenrow is pickrow. The chosencolumn is pickcolumn. The left is format whole number item chosenrow of firsts as text. The right is format whole number item chosencolumn of seconds as text. The line is empty text. Place left into line. Place "," into line. Place right into line. Place line into answers. Add 1 to round.
For each answer in answers, show answer.
Expected stdout
1,2 1,4 1,6