FastPrepResponse Time Across a City Grid
Problems/Response Time Across a City Grid

Response Time Across a City Grid

LinkedIn logoLinkedIn● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a LinkedIn onsite interview. The report describes a city matrix with several fire stations and a task about spread or response time. It is like a problem where many sources spread at once. Here, every station responds to all marked locations at the same time. We chose the cell codes, the travel rules, the goal, the function signature and the limits. Our version is about 75% the same as the reported question.

A rectangular city grid contains blocked cells (0), locations needing a response (1), and fire stations (2). Every station begins responding at time zero. A response can move one cell up, down, left, or right, taking one minute per step. It cannot enter a blocked cell. Stations operate simultaneously.

Return the earliest time at which every location marked 1 can be reached from some station. Return -1 if any such location cannot be reached. Return 0 when no location needs a response.

Station cells are passable.

Function

cityResponseTime(grid: int[][]) → int

Examples

Example 1

grid = [[2,1,1],[1,0,1],[1,1,2]]return = 2
grid
012021111012112

Both stations start together. Every marked location is within two steps of a station.

Example 2

grid = [[2,0,1]]return = -1
grid
0120201

The blocked cell separates the only location from the station.

Example 3

grid = [[0,2],[2,0]]return = 0
grid
01002120

No cell is marked as needing a response.

Constraints

  • 1 <= grid.length, grid[0].length <= 100.
  • All rows have the same length and contain only 0, 1 or 2.
  • A location is reached when a response first arrives; independent stations do not block each other.

More LinkedIn Onsite Interview questions

  • Allocate Mailboxes with Squared DistanceONSITE INTERVIEW · Seen Nov 2026
  • Find Leaves of a Binary TreeONSITE INTERVIEW · Seen Nov 2026
  • Max Points on a LineONSITE INTERVIEW · Seen Nov 2026
  • Explore an Unknown Grid and Find a PathONSITE INTERVIEW · Seen Nov 2026
  • Fire Station Response BillONSITE INTERVIEW · Seen Nov 2026
  • Roll a Weighted DieONSITE INTERVIEW · Seen Oct 2026
  • Longest Binary Subarray With at Most K OnesONSITE INTERVIEW · Seen Oct 2026
  • Kth Closest Element in a BSTONSITE INTERVIEW · Seen Oct 2026
  • Longest Binary Window with at Most K OnesONSITE INTERVIEW · Seen Oct 2026
  • LRU Cache OperationsONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Shortest Increasing Path to a TargetUber · ONSITE INTERVIEWUber interview questions
  • Minimum Distance to Return a BookGoogle · ONSITE INTERVIEWGoogle interview questions
  • Find and Reconstruct a Binary-Matrix PathMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Shortest Grid Path with Obstacle EliminationsAmazon · ONSITE INTERVIEW
  • Shortest Path in a Grid with Obstacles EliminationBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Shortest Travel Time in a Grid with Traffic LightsWaymo · PHONE SCREENWaymo interview questions
  • Shortest Path in a Blocked GridSpotify · PHONE SCREEN
  • Minimum MovesHarness · OA
  • Shortest Path Around Rectangular ObstaclesDRW · OADRW interview questions
  • Minimum Knight MovesMcKinsey & Company · OAMcKinsey & Company interview questions

LinkedIn interview experiences

  • LinkedIn Senior MLE Interview Questions: 1 Experience
  • LinkedIn Staff AI Engineer Phone Screens: 1 Experience
  • LinkedIn Experienced MLE Onsite: 1 Experience
  • LinkedIn Coding with AI Interview: 4 Experiences
  • LinkedIn Experienced Infrastructure SWE Onsite: 1 Experience
All LinkedIn interview questionsSee LinkedIn hiring insights
Saved
class Solution {
    public int cityResponseTime(int[][] grid) {
        // Write your code here.
    }

}
Checking account…