FastPrepSimulate Orchard Rot Spread

Simulate Orchard Rot Spread

ZipRecruiter logoZipRecruiter● MediumNEW GRADOA
Learn

Problem statement

An orchard is a rectangular array of strings using - for empty, T for healthy trees, and R for rotten trees.

Each day is synchronous: trees rotten at the start of the day infect orthogonally adjacent healthy trees; newly rotten trees begin spreading the next day.

Return the orchard after exactly days days.

Function

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

Examples

Example 1

orchard = ["RT-","TTT"]days = 1return = ["RR-","RTT"]

Only trees adjacent to the original rotten tree change on day one.

Example 2

orchard = ["R-T","TTT"]days = 0return = ["R-T","TTT"]

Zero days leaves the orchard unchanged.

Constraints

  • 1 <= rows,columns <= 200
  • 0 <= days <= 100000

More ZipRecruiter problems

See ZipRecruiter hiring insights
public String[] simulateOrchard(String[] orchard, int days) {
    // Write your code here.
}
orchard["RT-","TTT"]
days1
expected["RR-", "RTT"]
Checking account…