PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches
|Home/Coding & Algorithms/Uber

Compute time for virus to infect grid

Last updated: Apr 21, 2026

Quick Overview

This question evaluates a candidate's ability to reason about grid-based state propagation, algorithmic problem solving, and performance considerations when managing multi-step updates across a 2D matrix.

  • medium
  • Uber
  • Coding & Algorithms
  • Software Engineer

Compute time for virus to infect grid

Company: Uber

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given an `m x n` grid representing the state of individuals in a lab. - `0` = empty cell (no one) - `1` = healthy individual - `2` = infected individual Every minute, any **healthy** individual (`1`) that is **4-directionally adjacent** (up/down/left/right) to an infected individual (`2`) becomes infected. Return the **minimum number of minutes** needed until **no healthy individuals remain**. If it is **impossible** to infect all healthy individuals, return `-1`. If there are **no healthy individuals initially**, return `0`. ### Input - A 2D integer array `grid` of size `m x n`. ### Output - An integer: the minimum minutes to infect everyone, or `-1` if impossible. ### Constraints - `1 ≤ m, n ≤ 200` - `grid[i][j] ∈ {0,1,2}` ### Notes (as in the interview) - You may be asked to write your own test cases (including edge cases) to validate your solution.

Quick Answer: This question evaluates a candidate's ability to reason about grid-based state propagation, algorithmic problem solving, and performance considerations when managing multi-step updates across a 2D matrix.

Related Interview Questions

  • Implement stream queries and bounded-difference subarrays - Uber (medium)
  • Implement Minesweeper and Word Search - Uber (medium)
  • Implement Store Autocomplete - Uber (medium)
  • Simulate a Rank-Based Tournament - Uber (medium)
  • Implement Cache Eviction And Seat Assignment - Uber (medium)
Uber logo
Uber
Feb 12, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
17
0
Loading...

You are given an m x n grid representing the state of individuals in a lab.

  • 0 = empty cell (no one)
  • 1 = healthy individual
  • 2 = infected individual

Every minute, any healthy individual (1) that is 4-directionally adjacent (up/down/left/right) to an infected individual (2) becomes infected.

Return the minimum number of minutes needed until no healthy individuals remain. If it is impossible to infect all healthy individuals, return -1. If there are no healthy individuals initially, return 0.

Input

  • A 2D integer array grid of size m x n .

Output

  • An integer: the minimum minutes to infect everyone, or -1 if impossible.

Constraints

  • 1 ≤ m, n ≤ 200
  • grid[i][j] ∈ {0,1,2}

Notes (as in the interview)

  • You may be asked to write your own test cases (including edge cases) to validate your solution.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

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

Master your tech interviews with 7,500+ 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.