The TransCompilator

Solved LeetCode program · 505 of 1,000

#0710 · Random Pick with Blacklist

Hard Array chunk-11.md

Original English source

Keep a shared size of 5. Keep a shared blocked as an empty list of whole numbers. Place 1 into blocked. Keep a shared spare of 0. The lastblock is the last position of blocked. The blockedcount is lastblock plus 1. The allowed is size minus blockedcount. The mapping is a list of allowed zeros.

To seek from start (a whole number). If start is at least size, set spare to start, return. If blocked contains start, Seek from start plus 1, return. Set spare to start.

For every spot from 0 to lastblock.
The value is item spot of blocked. If value is less than allowed, Seek from allowed, Set item value of mapping to spare.

The seed is 2026.
For every pick from 0 to allowed minus 1.
Set seed to seed times 1103515245 plus 12345. Set seed to seed modulo 2147483648. The draw is seed modulo allowed. The chosen is item draw of mapping. If chosen is 0, set chosen to draw. Show chosen.

Open in Playground Browse all 1,000 problems

Expected stdout

3
0
4
2