PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Snowflake

Compute nearest bathroom distance for each desk

Last updated: Mar 29, 2026

Quick Overview

This question evaluates a candidate's ability to reason about shortest-paths and reachability on grid graphs, testing skills in graph traversal, distance computation, and spatial problem modeling within the Coding & Algorithms domain.

  • hard
  • Snowflake
  • Coding & Algorithms
  • Software Engineer

Compute nearest bathroom distance for each desk

Company: Snowflake

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Technical Screen

You are given an `m x n` grid of characters containing only: - `'B'` = bathroom - `'D'` = desk - `'_'` = empty cell From any cell you may move one step up/down/left/right (no diagonals). The distance between two cells is the length of the shortest such path. For every desk cell `'D'`, compute the distance to its nearest bathroom `'B'`. Return an `m x n` integer matrix where: - for a desk cell, the value is the nearest-bathroom distance, - for non-desk cells, you may return `-1` (or any clearly documented placeholder). If a desk cannot reach any bathroom, return `-1` for that desk.

Quick Answer: This question evaluates a candidate's ability to reason about shortest-paths and reachability on grid graphs, testing skills in graph traversal, distance computation, and spatial problem modeling within the Coding & Algorithms domain.

Related Interview Questions

  • Solve Array Distance and Wiki Navigation - Snowflake (medium)
  • Implement Document Predicate APIs - Snowflake (medium)
  • Find Shortest Wiki Click Path - Snowflake (medium)
  • Schedule prerequisite classes with retakes - Snowflake (easy)
  • Solve three coding rounds - Snowflake (medium)
Snowflake logo
Snowflake
Jan 16, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
5
0

You are given an m x n grid of characters containing only:

  • 'B' = bathroom
  • 'D' = desk
  • '_' = empty cell

From any cell you may move one step up/down/left/right (no diagonals). The distance between two cells is the length of the shortest such path.

For every desk cell 'D', compute the distance to its nearest bathroom 'B'.

Return an m x n integer matrix where:

  • for a desk cell, the value is the nearest-bathroom distance,
  • for non-desk cells, you may return -1 (or any clearly documented placeholder).

If a desk cannot reach any bathroom, return -1 for that desk.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Snowflake•More Software Engineer•Snowflake Software Engineer•Snowflake Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.