Solved LeetCode program · 574 of 1,000
#0801 · Minimum Swaps To Make Sequences Increasing
Original English source
The first is a list of 1, 3, 5, and 4. The second is a list of 1, 2, 3, and 7. The last is the last position of first. The keepnow is 0. The swapnow is 1. The newkeep is 0. The newswap is 0.
For every spot from 1 to last.
Set newkeep to 1000000. Set newswap to 1000000. The before is spot minus 1. If item before of first is less than item spot of first and item before of second is less than item spot of second and keepnow is less than newkeep, set newkeep to keepnow. If item before of first is less than item spot of first and item before of second is less than item spot of second and swapnow plus 1 is less than newswap, set newswap to swapnow plus 1. If item before of first is less than item spot of second and item before of second is less than item spot of first and swapnow is less than newkeep, set newkeep to swapnow. If item before of first is less than item spot of second and item before of second is less than item spot of first and keepnow plus 1 is less than newswap, set newswap to keepnow plus 1. Set keepnow to newkeep. Set swapnow to newswap.
If keepnow is less than swapnow, show keepnow, otherwise show swapnow.
Expected stdout
1