Solved LeetCode program · 641 of 1,000
#0870 · Advantage Shuffle
Original English source
Keep a shared numbers holding 2, 7, 11, and 15. Keep a shared aims holding 1, 10, 4, and 11. Keep a shared used holding 0, 0, 0, and 0. Keep a shared answers holding 0, 0, 0, and 0. Keep a shared pick of 0.
To seek from spot (a whole number) with aim (a whole number). If spot is more than the last position of numbers, return. If item spot of used is 1, seek from spot plus 1 with aim, return. If item spot of numbers is more than aim, set pick to spot, return. Seek from spot plus 1 with aim.
To spare from spot (a whole number). If spot is more than the last position of numbers, return. If item spot of used is 0, set pick to spot, return. Spare from spot plus 1.
Sort numbers. The place is 0.
For each aim in aims.
Set pick to -1. Seek from 0 with aim. If pick is equal to -1, Spare from 0. The chosen is pick. Set item chosen of used to 1. Set item place of answers to item chosen of numbers. Add 1 to place.
For each value in answers, show value.
Expected stdout
2 11 7 15