Solved LeetCode program · 815 of 1,000
#1054 · Distant Barcodes
Original English source
Keep a shared labels as an empty list of whole numbers. Keep a shared counts as an empty list of whole numbers. Keep a shared wanted of 0. Keep a shared located of 0. Keep a shared best of 0. Keep a shared bestcount of 0. Keep a shared previous of -1.
To locate from spot (a whole number). If spot is more than the last position of labels, return. If item spot of labels is wanted, set located to spot, return. Locate from spot plus 1.
The barcodes is a list of 1, 1, 1, 2, 2, and 3.
For each code in barcodes.
Set wanted to code. Set located to -1. Locate from 0. The place is located. If place is at least 0, set item place of counts to item place of counts plus 1. If place is less than 0, Place code into labels, Place 1 into counts.
To pick. Set best to 0. Set bestcount to -1.
For every spot from 0 to the last position of labels.
The label is item spot of labels. The amount is item spot of counts. If label is not previous and amount is more than bestcount, set best to spot, set bestcount to amount.
The result is an empty list of whole numbers.
For every position from 0 to the last position of barcodes.
Pick. The spot is best. The chosen is item spot of labels. Place chosen into result. The place is best. Decrease item place of counts by 1. Set previous to chosen.
For each code in result, Show code.
Expected stdout
1 2 1 2 1 3