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.
Input: (["ST"],)
Expected Output: True
Explanation: This single-row edge case is reachable immediately by moving one step to the right.
Input: (["S#..", ".#.#", ".#T#", "...."],)
Expected Output: True
Explanation: Although direct paths are blocked, the character can go around through the bottom row to reach T.
Input: (["S", ".", "#", "T"],)
Expected Output: False
Explanation: In this single-column edge case, the obstacle blocks the only route to the target.
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.