Virus Spread (Intuit India)

Problem Overview

  • Find the minimum seconds for a virus to infect all cells in an N×M grid, or return -1 if some stay uninfected.
  • Input: N, M, and a matrix with 0 (empty), 1 (healthy), 2 (virus); Output: integer time or -1; Constraints: 1≤N,M≤100.
  • Infection spreads each second to up, down, left, and right neighbors only.
  • Real-world context: simulates virus spread in a petri dish.
  • Asked in Intuit India interviews; a classic coding interview problem and interview question.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: