2dbi
Home/Broadcom/Shortest Path Between Two Points in a 2D Matrix
BBroadcom·DSASDE-2Onsite – Coding 1

Shortest Path Between Two Points in a 2D Matrix

Problem

Given a grid with blocked cells, find the shortest path length between two points (4-directional moves).

Example

BFS from source until target reached

Constraints

  • 1 ≤ m,n ≤ 500

Follow-up

Weighted cells -> Dijkstra; allow breaking up to k walls -> 3D BFS state.

added 6 days ago
LeadersAccount