PracHub
QuestionsPremiumLearningGuidesCheatsheetNEW
|Home/Coding & Algorithms/OpenAI

Minimize deaths in spreading plant infection

Last updated: Apr 19, 2026

Quick Overview

This question evaluates a candidate's ability to model and simulate dynamic grid processes, reason about infection propagation and delayed state changes, and incorporate constrained intervention decisions.

  • medium
  • OpenAI
  • Coding & Algorithms
  • Software Engineer

Minimize deaths in spreading plant infection

Company: OpenAI

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given an `m x n` grid representing a garden: - `0`: empty cell - `1`: healthy plant - `2`: infected plant The garden evolves day by day in the following order: 1. At the start of the day, you may optionally perform one intervention: burn exactly one entire row or one entire column. Every plant in that line is removed immediately. Burned cells become empty forever. 2. Each infected plant spreads the infection to its orthogonally adjacent healthy neighbors. 3. After the spread, check each infected plant. If an infected plant has ever had at least `K` orthogonally adjacent infected neighbors at the end of a day, it becomes marked for death. 4. A marked plant dies exactly `D` days after the first day it was marked, and the cell becomes empty. Assume that once a plant is marked, its death timer does not reset. Dead or burned cells do not spread infection, cannot be infected again, and are not counted as infected neighbors. Answer both parts: 1. Given the initial grid, `K`, and `D`, compute how many plants eventually die because of the overcrowding rule. 2. You may use the burn intervention at most once, on any chosen day. Burned plants are not counted as deaths. Design an algorithm to choose the best day and the best row or column to burn so that the number of eventual deaths is minimized.

Quick Answer: This question evaluates a candidate's ability to model and simulate dynamic grid processes, reason about infection propagation and delayed state changes, and incorporate constrained intervention decisions.

Related Interview Questions

  • Simulate Infection Spread on a Grid - OpenAI (hard)
  • Implement Social Follow Recommendations - OpenAI (medium)
  • Build a Compose Rating Card - OpenAI (medium)
  • Generate Data Labeling Schedules - OpenAI (medium)
  • Convert IPv4 Ranges to CIDR Blocks - OpenAI (medium)
OpenAI logo
OpenAI
Apr 1, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
96
0
Coding Console
Loading...

You are given an m x n grid representing a garden:

  • 0 : empty cell
  • 1 : healthy plant
  • 2 : infected plant

The garden evolves day by day in the following order:

  1. At the start of the day, you may optionally perform one intervention: burn exactly one entire row or one entire column. Every plant in that line is removed immediately. Burned cells become empty forever.
  2. Each infected plant spreads the infection to its orthogonally adjacent healthy neighbors.
  3. After the spread, check each infected plant. If an infected plant has ever had at least K orthogonally adjacent infected neighbors at the end of a day, it becomes marked for death.
  4. A marked plant dies exactly D days after the first day it was marked, and the cell becomes empty.

Assume that once a plant is marked, its death timer does not reset. Dead or burned cells do not spread infection, cannot be infected again, and are not counted as infected neighbors.

Answer both parts:

  1. Given the initial grid, K , and D , compute how many plants eventually die because of the overcrowding rule.
  2. You may use the burn intervention at most once, on any chosen day. Burned plants are not counted as deaths. Design an algorithm to choose the best day and the best row or column to burn so that the number of eventual deaths is minimized.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More OpenAI•More Software Engineer•OpenAI Software Engineer•OpenAI Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.