The TransCompilator

Solved LeetCode program · 827 of 1,000

#1091 · Shortest Path in Binary Matrix

Medium Array chunk-17.md

Original English source

The board is a list of 0, 0, 0, 1, 1, 0, 1, 1, and 0. The side is 3. The downsteps is a list of -1, -1, -1, 0, 0, 1, 1, and 1. The sidesteps is a list of -1, 0, 1, -1, 1, -1, 0, and 1. The distances is a list of 9 zeros. The queue is a list of 81 zeros. The head is 0. The count is 0. The answer is -1.
If item 0 of board is 0.
Set item 0 of distances to 1. Set item 0 of queue to 0. Set count to 1.

Repeat while head is less than count.
The node is item head of queue. Add 1 to head. The band is node divided by side. The column is node modulo side. The depth is item node of distances plus 1.
For every step from 0 to 7.
The nextband is band plus item step of downsteps. The nextcolumn is column plus item step of sidesteps.
If nextband is at least 0 and nextband is less than side and nextcolumn is at least 0 and nextcolumn is less than side.
The target is nextband times side plus nextcolumn.
If item target of board is 0 and item target of distances is 0.
Set item target of distances to depth. Set item count of queue to target. Add 1 to count.

If item 8 of distances is more than 0, set answer to item 8 of distances. Show answer.

Open in Playground Browse all 1,000 problems

Expected stdout

4