OpenAI Interview Coding Question: Infected Plant Spread Simulation with Healing and Immunity Updates

15 Views
No Comments

An infected plant spreads infection to neighboring plants. If a plant is surrounded by D infected plants, it also becomes infected. How many days until all plants are infected?

Follow-up: some plants can become infection-proof after the infection changes. What update is needed?

Follow-up: after K days, an infected plant can be healed and become infection-proof. What update is needed?

This is a contagion spread simulation on a grid or graph: infection expands day by day from initially infected plants, and a plant becomes infected once it has at least D infected neighbors. A standard solution uses multi-source BFS to propagate infection level by level and record the day each plant changes state, which gives the total time until the whole field is infected. The follow-ups add state transitions: some plants become infection-proof after infection, and infected plants may heal after K days and become immune, so the simulation needs a queue or event-driven model that tracks infection, immunity, and healing carefully.

END
 0