Can the character reach the destination?
Company: Roblox
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates understanding of graph traversal and reachability in grid-based pathfinding, covering skills such as modeling a 2D grid as a graph, handling obstacles and boundary conditions, and algorithmic traversal strategies.
Constraints
- 1 <= m, n
- All rows in grid have the same length
- grid[i][j] is one of 'S', 'T', '#', or '.'
- Exactly one 'S' and exactly one 'T' exist in the grid
Examples
Input: (["S..", ".#.", "..T"],)
Expected Output: True
Explanation: A valid path exists around the obstacle: down, down, right, right.
Input: (["S#.", "##.", "..T"],)
Expected Output: False
Explanation: The start cell is completely blocked by obstacles, so no movement is possible.
Hints
- Think of each open cell as a node in a graph connected to its up, down, left, and right neighbors.
- Use BFS or DFS and keep track of visited cells so you do not process the same cell multiple times.