Grokking 75: Top Coding Interview Questions
Ask Author
Back to course home

0% completed

Shortest Path in a Grid with Obstacles Elimination (hard)
Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Problem Statement

You are given an m x n binary matrix grid where each cell is either empty (0) or has an obstacle (1). You can move up, down, left, or right, but only through empty cells. You can remove up to k obstacles along the way.

Return the shortest path from the top-left corner (0, 0) to the bottom-right corner (m - 1, n - 1). If it's not possible to reach the end, return -1.

Examples

Example 1

  • Input: k = 1, grid =
[[0, 1, 0, 0],
 [1, 1, 0, 1],
 [0, 0, 0, 0],
 [0, 1, 1, 0]]

  • Expected Output: 6

.....

.....

.....

Like the course? Get enrolled and start learning!

Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible