The TransCompilator

Solved LeetCode program · 690 of 1,000

#0924 · Minimize Malware Spread

Hard Array chunk-14.md

Original English source

Keep a shared edges holding 1 and 0. Keep a shared starts holding 0, 1, and 2. Keep a shared counts holding 1, 1, and 0. Keep a shared initial holding 0 and 1. Keep a shared infected holding 0, 0, and 0. Keep a shared banned of 0. Keep a shared total of 0.

To spread. For every node from 0 to 2, set item node of infected to 0. Set total to 0. The queue is an empty list of whole numbers. For each seed in initial, if seed is not banned and item seed of infected is 0, set item seed of infected to 1, add 1 to total, Place seed into queue. The head is 0.
Repeat while head is at most the last position of queue.
The node is item head of queue. Add 1 to head.
For every offset from 0 to item node of counts minus 1.
The next is item (item node of starts plus offset) of edges. If item next of infected is 0, set item next of infected to 1, add 1 to total, Place next into queue.

The best is 4. The answer is -1.
For each candidate in initial.
Set banned to candidate. Spread. If total is less than best, set best to total, set answer to candidate. If total is best and candidate is less than answer, set answer to candidate.

Report answer.

Open in Playground Browse all 1,000 problems

Expected stdout

0