FastPrepSimulate Orchard Rot Spread
Problems/Simulate Orchard Rot Spread

Simulate Orchard Rot Spread

Capital One logoCapital One● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Capital One online assessment. The task was to simulate rot spreading through an orchard grid for a given number of days, where each rotten tree rots the healthy trees next to it every day, and return the final grid.

The report gives no limits on the grid size or the number of days. Here, the grid has 1 to 50 rows and columns, and days is between 0 and 1000, so the simple day-by-day approach fits the time limit.

Our version is about 95% the same as the reported question.

Given a 2D grid orchard and an integer days, simulate how rot spreads through the orchard for days days and return the state of the orchard after the last day.

Each cell of orchard holds one character:

  • '-': an empty cell.
  • 'T': a healthy tree.
  • 'R': a rotten tree.

Each day, rot spreads from every rotten tree to its adjacent cells (up, down, left and right), so every healthy tree next to a rotten tree becomes rotten. Empty cells stay empty. A tree that becomes rotten on a day starts spreading rot on the next day.

Note: You don't need the most optimal solution. Any solution with time complexity no worse than O(days * rows * cols) fits within the time limit, where rows and cols are the number of rows and columns in orchard.

Function

simulateOrchard(orchard: char[][], days: int) → char[][]

Examples

Example 1

orchard = [["T","R","-","-"],["-","T","T","R"],["T","T","-","R"],["-","-","R","-"]]days = 2return = [["R","R","-","-"],["-","R","R","R"],["T","R","-","R"],["-","-","R","-"]]
orchard
01230TR--1-TTR2TT-R3--R-
→
return
01230RR--1-RRR2TR-R3--R-
Moved or new

Cells are written as (row, column).

  • Day 1: the rotten trees at (0, 1) and (1, 3) rot the healthy trees at (0, 0), (1, 1) and (1, 2).
  • Day 2: the tree at (1, 1), rotten since day 1, rots the tree at (2, 1). The tree at (2, 0) stays healthy, because (2, 1) only became rotten on day 2.

Example 2

orchard = [["R","T","-","T"],["-","T","-","T"]]days = 3return = [["R","R","-","T"],["-","R","-","T"]]
orchard
01230RT-T1-T-T
→
return
01230RR-T1-R-T
Moved or new

Rot reaches (0, 1) on day 1 and (1, 1) on day 2, then has no healthy tree left to reach. Empty cells cut off the two trees in the last column, so they stay healthy.

Example 3

orchard = [["T","R"],["T","T"]]days = 0return = [["T","R"],["T","T"]]
orchard
010TR1TT
→
return
010TR1TT

With days = 0, no day passes, so the orchard is returned unchanged.

Constraints

  • 1 <= orchard.length <= 50
  • 1 <= orchard[i].length <= 50
  • All rows of orchard have the same length.
  • orchard[i][j] is '-', 'T', or 'R'.
  • 0 <= days <= 1000

More Capital One Online Assessment questions

  • Count Pairs of Overlapping SquaresOA · Seen Nov 2026
  • Distinct Values on Maximum-Sum FramesOA · Seen Nov 2026
  • Lowest Number in an Open RangeOA · Seen Nov 2026
  • Branch with the Most FilesOA · Seen Nov 2026
  • Earliest Meeting Time for All EmployeesOA · Seen Nov 2026
  • Earn the Most 🐝OA · Seen Nov 2026
  • Rank Football TeamsOA · Seen Oct 2026
  • Count Subarrays Matching a Comparison PatternOA · Seen Oct 2026
  • Arithmetic Triplets After QueriesOA · Seen Oct 2026
  • Count One-Swap Number PairsOA · Seen Oct 2026

Similar questions at other companies

  • Simulate Orchard Rot SpreadAirbnb · OAAirbnb interview questions
  • Simulate Orchard Rot SpreadZipRecruiter · OAZipRecruiter interview questions
  • Competitive ForagingAkuna Capital · OAAkuna Capital interview questions
  • Explore an Unknown Grid and Find a PathLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
  • Grid Infection with Recovery After D DaysOpenAI · PHONE SCREENOpenAI interview questions
  • Days Until Poisoned Plants StabilizeApple · PHONE SCREENApple interview questions
  • Process Minesweeper Game OperationsAmperity · PHONE SCREENAmperity interview questions
  • Minesweeper Board UpdateUber · ONSITE INTERVIEWUber interview questions
  • Xiangqi Horse ReachabilityeBay · PHONE SCREENeBay interview questions
  • Minesweeper Board UpdateClay · ONSITE INTERVIEW

Capital One interview experiences

  • Capital One Coding OA Questions: 3 Experiences
  • Capital One Experienced Engineer Power Day and OA: 6 Experiences
  • Capital One New Grad OA Questions: 14 Experiences (Part 2 of 2)
  • Capital One TDP Agentic Round (AI Coding): 7 Experiences
  • Capital One SWE Power Day, Level Not Reported: 6 Experiences
  • Capital One TIP Intern OA and Power Day: 13 Experiences
All Capital One interview questionsSee Capital One hiring insights
Saved
class Solution {
    public char[][] simulateOrchard(char[][] orchard, int days) {
      // write your code here
    }
}
Checking account…