Solved LeetCode program · 826 of 1,000
#1090 · Largest Values From Labels
Original English source
The values is a list of 5, 4, 3, 2, and 1. The labels is a list of 1, 1, 2, 2, and 3. The wanted is 3. The limit is 1. The ranked is an empty list of whole numbers. The tags is an empty list of whole numbers.
For every spot from 0 to the last position of values.
The value is item spot of values. The tag is item spot of labels. Place value into ranked. Place tag into tags. The place is the last position of ranked.
Repeat while place is more than 0 and item (place minus 1) of ranked is less than value.
Set item place of ranked to item (place minus 1) of ranked. Set item place of tags to item (place minus 1) of tags. Subtract 1 from place. Set item place of ranked to value. Set item place of tags to tag.
The used is a list of 4 zeros. The total is 0. The taken is 0.
For every spot from 0 to the last position of ranked.
If taken is less than wanted.
The tag is item spot of tags.
If item tag of used is less than limit.
Increase item tag of used by 1. The value is item spot of ranked. Add value to total. Add 1 to taken.
Show total.
Expected stdout
9