First, we need to count the number of primes that are missing from the given array. There are only 1229 primes in the first 10000 integers. We can generate them once using the Sieve of Eratosthenes. Then we can apply a dynamic programming approach with two parameters: the index of the current position and the number of primes that are still at hand. It is redundant to keep track of the non-primes that are still to be placed, as it can be easily calculated from the DB parameters.

Statistics

30% Solution Ratio
ashikurrahmanEarliest, Feb '20
Kuddus.6068Fastest, 0.0s
chieloLightest, 131 kB
ashikurrahmanShortest, 1979B
Toph uses cookies. By continuing you agree to our Cookie Policy.