PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches
|Home/Coding & Algorithms/Amazon

Compute grid shortest path with obstacles

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of grid-based graph traversal, shortest-path reasoning, and obstacle handling, testing competence in algorithmic problem-solving and complexity analysis within the Coding & Algorithms domain.

  • Medium
  • Amazon
  • Coding & Algorithms
  • Software Engineer

Compute grid shortest path with obstacles

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Technical Screen

You are given an m x n grid of integers where cells with value -1 represent obstacles and all other cells are traversable. Starting at (0, 0) and targeting (m-1, n- 1), compute the length of the shortest path using only four-directional moves (up, down, left, right). Return -1 if the target is unreachable. Describe your algorithm, prove its correctness at a high level, analyze time and space complexities, cover edge cases (e.g., blocked start/goal, single-cell grid), and provide pseudocode.

Quick Answer: This question evaluates understanding of grid-based graph traversal, shortest-path reasoning, and obstacle handling, testing competence in algorithmic problem-solving and complexity analysis within the Coding & Algorithms domain.

Related Interview Questions

  • Count Connected Components in an Undirected Graph - Amazon (medium)
  • Find Unique Target-Sum Pairs - Amazon (easy)
  • Find Valid IP Addresses in Files - Amazon (medium)
  • Implement Optimal Bucket Batching - Amazon (hard)
  • Implement Cache and Rotate Matrix - Amazon (medium)
Amazon logo
Amazon
Sep 6, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
2
0

You are given an m x n grid of integers where cells with value -1 represent obstacles and all other cells are traversable. Starting at (0, 0) and targeting (m-1, n- 1), compute the length of the shortest path using only four-directional moves (up, down, left, right). Return -1 if the target is unreachable. Describe your algorithm, prove its correctness at a high level, analyze time and space complexities, cover edge cases (e.g., blocked start/goal, single-cell grid), and provide pseudocode.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

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