๐ Google SDE-3 Interview Question | Graphs + BFS | CTC โน65โ85 LPA
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 :)