PracHub
QuestionsPremiumLearningGuidesCheatsheetNEW
|Home/Coding & Algorithms/Snapchat

Compute shortest path in a 2D grid

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of graph traversal and pathfinding concepts, including modeling a 2D grid as a graph and reasoning about shortest-path computations and obstacle handling.

  • hard
  • Snapchat
  • Coding & Algorithms
  • Software Engineer

Compute shortest path in a 2D grid

Company: Snapchat

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Onsite

Given an `m x n` grid where: - `0` represents an empty cell you can move through - `1` represents a blocked cell you cannot enter - movement is allowed in 4 directions (up, down, left, right) You are also given coordinates `start = (sr, sc)` and `target = (tr, tc)` (both are inside the grid). Return the length of the shortest path (number of moves) from `start` to `target`. If `target` is unreachable, return `-1`. Explain the algorithm you would use and its time/space complexity.

Quick Answer: This question evaluates understanding of graph traversal and pathfinding concepts, including modeling a 2D grid as a graph and reasoning about shortest-path computations and obstacle handling.

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
Jan 4, 2026, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
1
0

Given an m x n grid where:

  • 0 represents an empty cell you can move through
  • 1 represents a blocked cell you cannot enter
  • movement is allowed in 4 directions (up, down, left, right)

You are also given coordinates start = (sr, sc) and target = (tr, tc) (both are inside the grid).

Return the length of the shortest path (number of moves) from start to target. If target is unreachable, return -1.

Explain the algorithm you would use and its time/space complexity.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

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