Solve the following two coding problems.
-
Count disconnected land regions
-
You are given an
m x n
grid of characters where
'1'
represents land and
'0'
represents water.
-
A region is formed by connecting land cells horizontally or vertically.
-
Return the number of distinct land regions in the grid.
-
Compute infection time in a grid
-
You are given an
m x n
grid where:
-
0
= empty cell
-
1
= fresh item
-
2
= infected item
-
Every minute, each infected item spreads infection to its adjacent fresh items in the four cardinal directions.
-
Return the minimum number of minutes required until no fresh item remains.
-
If it is impossible to infect all fresh items, return
-1
.
The interview note suggests medium-to-upper-medium difficulty and primarily tests graph traversal on grids, especially DFS, BFS, and multi-source BFS.