๐Ÿš€ Google SDE-3 Interview Question | Graphs + BFS | CTC โ‚น65โ€“85 LPA

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2025-09-20Added By Anonymous
Source:ย Link

Company: Google
Role: SDE-3
Interview Stage: unknown
Location: unknown
Year: unknown

Original Post Content:

Video Solution for the problem - https://www.youtube.com/watch?v=sxch8fSvkAw (found it recently)

You are given a city represented as an N ร— M grid. Each cell can be one of the following:
'.' โ†’ an empty road (walkable)
'#' โ†’ a blocked building (not walkable)
'S' โ†’ starting position of the rescue team
'E' โ†’ the exit point that must be reached
'F' โ†’ a fire source

๐Ÿ”ฅ Fire Spread Rules:
Fire spreads to all 4-neighbors (up, down, left, right) every minute.

๐Ÿง‘โ€๐Ÿš’ Rescue Team Rules:
The rescue team can also move to 4-neighbors every minute (only into '.' or 'E').
The team cannot enter or stay in a cell once fire has reached it.

๐ŸŽฏ Goal:
Determine whether the rescue team can reach E before the fire catches up.
If yes, print the minimum time needed. Otherwise, print -1.

โœ… Input Format
T โ†’ number of test cases
N M โ†’ grid dimensions
Grid โ†’ N lines of M characters

โœ… Output Format

For each test case, print the minimum time to reach exit, or -1 if impossible.

๐Ÿ” Follow-up

Multiple cells may initially contain fire 'F'.

Anyone has solution for it ? - Thankyou :)

Comments