BFS Shortest Distance on a 2D Grid

You are given a 2D grid grid of size m x n. Use BFS to compute shortest distance on the grid.

Implement a function that computes the shortest distance by moving in **4 directions (up/down/left/ri...

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Standard Input
Execution Result: