Simulate Threshold Grid Infection
Company: Sealth
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates understanding of discrete grid-based simulations and local state-transition rules, focusing on modeling infection spread, neighbor-count constraints, and reasoning about convergence and stability in cellular-automata-like systems.
Constraints
- Inputs are Python literals matching the function signature.
- Return a deterministic exact-match value.
Examples
Input: ([[1,0],[0,0]], 1)
Expected Output: -1
Explanation: Infection spreads one-neighbor cells first.
Input: ([[1,0],[0,0]], 4)
Expected Output: -1
Explanation: Stable with healthy cells returns -1.
Input: ([[1,1]], 1)
Expected Output: 0
Explanation: Already all infected takes zero steps.
Hints
- Clarify edge cases before coding.
- Keep the return value deterministic.