Your Dashboard
Interview Coaching
Learn
System Design
ML System Design
Code
Behavioral
Salary Negotiation
Interview Guides
Leetcode 749. Contain Virus
Simulate days on an m×n grid where infected cells spread 4-directionally: each day identify all connected infected regions, compute for each the set of uninfected cells it would infect and the walls required to quarantine it, then greedily build walls around the region that threatens the most cells and let the others spread. Return the total number of walls built until no region can spread (or the grid becomes fully infected).
Asked at:
Uber
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
Mid January, 2025
Uber
Mid-level
Given a network of computers represented by an m x n matrix. Computers are either turned off (0), turned on (1) or infected by a virus (-1). Only turned on computers can get infected. Every hour, the neighboring computers of infected computer will get infected. Find the minimum number of hours at which the network will get completely infected. If that cannot happen, return -1. There may be more than one infected computers to start with.
Comments
Hello Interview Premium
Your account is free and you can post anonymously if you choose.