PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Snapchat

Find nearest room; extend to two users

Last updated: Mar 29, 2026

Quick Overview

This question evaluates competency in grid-based shortest-path algorithms, graph traversal, reachability analysis, and distance aggregation for multiple sources.

  • Medium
  • Snapchat
  • Coding & Algorithms
  • Machine Learning Engineer

Find nearest room; extend to two users

Company: Snapchat

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Technical Screen

You are given an m×n grid where 1 is a wall (impassable), 0 is an empty cell, and 2 is a meeting room. From a starting coordinate [r, c], you may move up, down, left, or right with cost 1 per step. Return the coordinates of the closest meeting room reachable from the start; if none are reachable, return [-1, -1]. Use the example grid [[0,0,1,0],[0,2,1,0],[0,2,1,0]] with start [0,0] where the expected output is [1,1]. Discuss your algorithm and time/space complexity. Follow-up: given two starting users s1 and s2, return the meeting room that minimizes the sum of their shortest-path distances (consider only rooms reachable by both) and also return that minimum total distance. Explain your approach and complexity.

Quick Answer: This question evaluates competency in grid-based shortest-path algorithms, graph traversal, reachability analysis, and distance aggregation for multiple sources.

Related Interview Questions

  • Determine Whether Courses Can Be Completed - Snapchat (medium)
  • Solve Decimal Coin Change - Snapchat (medium)
  • Find Maximum Island Perimeter - Snapchat (medium)
  • Solve Three Algorithmic Tasks - Snapchat (hard)
  • Implement a Timestamped Counter - Snapchat (medium)
Snapchat logo
Snapchat
Aug 13, 2025, 12:00 AM
Machine Learning Engineer
Technical Screen
Coding & Algorithms
1
0

You are given an m×n grid where 1 is a wall (impassable), 0 is an empty cell, and 2 is a meeting room. From a starting coordinate [r, c], you may move up, down, left, or right with cost 1 per step. Return the coordinates of the closest meeting room reachable from the start; if none are reachable, return [-1, -1]. Use the example grid [[0,0,1,0],[0,2,1,0],[0,2,1,0]] with start [0,0] where the expected output is [1,1]. Discuss your algorithm and time/space complexity. Follow-up: given two starting users s1 and s2, return the meeting room that minimizes the sum of their shortest-path distances (consider only rooms reachable by both) and also return that minimum total distance. Explain your approach and complexity.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Snapchat•More Machine Learning Engineer•Snapchat Machine Learning Engineer•Snapchat Coding & Algorithms•Machine Learning 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.