Simulate Orchard Rot Spread
Updated
Problem statement
Given an orchard grid orchard and an integer days, return the orchard after exactly days days.
The orchard is a rectangular array of strings. Each character is - for an empty cell, T for a healthy tree, or R for a rotten tree.
Each day, every tree that is rotten at the start of the day rots its healthy neighbors directly above, below, left, and right. All changes in a day happen at the same time, so a tree that rots today starts spreading rot the next day.
Function
simulateOrchard(orchard: String[], days: int) → String[]Examples
Example 1
orchard = ["RT-","TTT"]days = 1return = ["RR-","RTT"]The rotten tree at the top-left rots the tree to its right and the tree below it. The other trees are not next to it, so they stay healthy.
Example 2
orchard = ["R-T","TTT"]days = 0return = ["R-T","TTT"]Zero days leaves the orchard unchanged.
Example 3
orchard = ["TR--","-TTR","TT-R","--R-"]days = 2return = ["RR--","-RRR","TR-R","--R-"]Cells are named (row, column), counting from 0. The trees at (2, 3) and (3, 2) start rotten, but they have no healthy neighbors, so they never rot anything. On day 1, the rotten tree at (0, 1) rots (0, 0) and (1, 1), and the rotten tree at (1, 3) rots (1, 2). On day 2, (1, 1) rots (2, 1). The tree at (2, 0) touches only (2, 1), which rotted on day 2, so it is still healthy after day 2.
Constraints
1 <= rows,columns <= 500 <= days <= 1000
More Airbnb Online Assessment questions
- Count Card Duel RoundsOA · Seen Nov 2026
- Count Lamps Lighting Each PointOA · Seen Nov 2026
- Sort Adjacent PairsOA · Seen Nov 2026
- In-Memory File SystemOA · Seen Nov 2026
- Task Management SystemOA · Seen Nov 2026
- Recipe Management SystemOA · Seen Nov 2026
- Progressive Banking SystemOA · Seen Nov 2026
- Credit Accounts with Scheduled TransfersOA · Seen Oct 2026
- Parcel Attribute Store with TTLOA · Seen Oct 2026
- Parcel Event TrackingOA · Seen Oct 2026
Similar questions at other companies
- Simulate Orchard Rot SpreadCapital One · OACapital One 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
Airbnb interview experiences
- Airbnb OA · November 2026
- Airbnb Campus and Full-Time SWE OA / Interviews: 9 Experiences
- Airbnb Intern Phone Interviews: 21 Experiences (Part 7 of 7)
- Airbnb Intern OA and Phone Screens: 17 Experiences (Part 6 of 7)
- Airbnb Intern OA and Onsite Rounds: 16 Experiences (Part 5 of 7)
- Airbnb Intern OA, Diplomacy Game: 19 Experiences (Part 4 of 7)