Free beta: free to use with daily limits while we build. Join the waitlist for founding-member pricing at launch. Join the waitlist

Sign up free

Lyft interview question

Find how many minutes an infection needs to reach every fresh cell of a grid

Company:
Lyft
Type:
Coding
Difficulty:
Medium
Reported:
October 19, 2026

Problem

You are given an m x n grid where each cell holds one of three values:

  • 0: an empty cell,
  • 1: a fresh cell,
  • 2: an infected cell.

Every minute, each fresh cell that shares an edge (up, down, left or right) with an infected cell becomes infected. Return the minimum number of minutes after which no fresh cell remains. If some fresh cell can never be infected, return -1. If there are no fresh cells at the start, return 0.

Example 1

Input: grid = [[2, 1, 0],
               [1, 1, 0],
               [0, 1, 1]]
Output: 4

The infection reaches (0, 1) and (1, 0) in minute 1, (1, 1) in minute 2, (2, 1) in minute 3 and (2, 2) in minute 4.

Example 2

Input: grid = [[2, 0, 1],
               [1, 1, 0]]
Output: -1

The fresh cell in the top-right corner is surrounded by empty cells and the border, so the infection never reaches it.

Constraints

  • 1 <= m, n <= 10
  • Every cell is 0, 1 or 2.

Reported by candidates or drawn from publicly available sources, and rewritten in our own words. Pathwise Prep does not publish confidential assessment content. Report a concern