PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Sealth

Simulate Threshold Grid Infection

Last updated: Apr 16, 2026

Quick Overview

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.

  • medium
  • Sealth
  • Coding & Algorithms
  • Software Engineer

Simulate Threshold Grid Infection

Company: Sealth

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given an `m x n` binary grid where `1` means infected and `0` means healthy, along with an integer `K`. The system evolves in discrete time steps. During each step, all updates happen simultaneously: - An infected cell stays infected. - A healthy cell becomes infected if and only if exactly `K` of its four orthogonal neighbors (`up`, `down`, `left`, `right`) are infected at the start of that step. - Neighbors outside the grid do not count. Write a function that returns the minimum number of time steps needed for all cells to become infected. If the process reaches a stable state and some cells are still healthy, return `-1`. You may assume the grid is non-empty.

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.

Related Interview Questions

  • Implement one-cluster k-means - Sealth (easy)
  • Decode Ambiguous Morse Messages - Sealth (medium)
Sealth logo
Sealth
Mar 13, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
2
0
Loading...

You are given an m x n binary grid where 1 means infected and 0 means healthy, along with an integer K.

The system evolves in discrete time steps. During each step, all updates happen simultaneously:

  • An infected cell stays infected.
  • A healthy cell becomes infected if and only if exactly K of its four orthogonal neighbors ( up , down , left , right ) are infected at the start of that step.
  • Neighbors outside the grid do not count.

Write a function that returns the minimum number of time steps needed for all cells to become infected. If the process reaches a stable state and some cells are still healthy, return -1.

You may assume the grid is non-empty.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Sealth•More Software Engineer•Sealth Software Engineer•Sealth Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.