Walking Distance From Every Park Path to the Nearest Restroom

Last updated: November 29, 2026

Quick Overview

Given a park grid where 'R' is a restroom, '.' is an open walkway and '#' is a closed area, return a grid of the minimum number of steps from each walkway cell to its nearest restroom, using -1 for closed or unreachable cells.

Disney
Coding & Algorithms
Software Engineer
Disney
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Given a park grid where 'R' is a restroom, '.' is an open walkway and '#' is a closed area, return a grid of the minimum number of steps from each walkway cell to its nearest restroom, using -1 for closed or unreachable cells.

A grid problem in the style of Disney Parks digital teams who build wayfinding in the My Disney Experience app. The interviewer checks that you start BFS from all restrooms at once instead of running one search per cell.

What the Interviewer Expects
  • Recognize multi-source BFS
  • Seed the queue with every restroom at distance 0
  • Mark cells visited when enqueued, not when dequeued
  • Respect closed cells and grid bounds
  • Explain O(rows x cols) complexity versus per-cell BFS
Key Topics to Cover
BFS
multi-source BFS
grids
shortest paths
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Paths have different walking costs; what changes?
  • A restroom closes for cleaning; how do you update distances without a full recompute?
  • How would you also return which restroom is nearest?
  • How would this work on a real path graph rather than a grid?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Grid of strings with R, ., #. Movement is 4-directional with unit cost. Output is a same-sized integer grid: 0 on restrooms, shortest step count on reachable walkways, and -1 on closed or unreac...

High-Level Design

Running BFS from every walkway costs O((RC)^2). Reverse the question: start one BFS from all restrooms simultaneously. BFS expands in rings of equal distance, so the first time a cell is reached is fr...


Submit Your Answer
Markdown supported

Related Questions