The TransCompilator

Solved LeetCode program · 930 of 1,000

#1293 · Shortest Path in a Grid with Obstacles Elimination

Hard Array chunk-19.md

Original English source

Keep a shared cells holding 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, and 0. Keep a shared best as an empty list of whole numbers. For every spot from 0 to 14, Place -1 into best. Keep a shared queue as an empty list of whole numbers. Keep a shared remaining as an empty list of whole numbers. Keep a shared distances as an empty list of whole numbers. Keep a shared tally of 1. Keep a shared leftnow of 0. Keep a shared stepsnow of 0.

To probe from other (a whole number). If other is less than 0 or other is more than 14, return. The cost is 0. If item other of cells is 1, set cost to 1. The after is leftnow minus cost. If after is less than 0, return. If after is at most item other of best, return. Set item other of best to after. Place other into queue. Place after into remaining. Place stepsnow plus 1 into distances. Add 1 to tally.

Set item 0 of best to 1. Place 0 into queue. Place 1 into remaining. Place 0 into distances. The head is 0. The answer is -1.
Repeat while head is less than tally.
The here is item head of queue. The left is item head of remaining. The steps is item head of distances. Add 1 to head. If here is 14, set answer to steps, stop. The band is here divided by 3. The file is here modulo 3. The west is here minus 1. The east is here plus 1. The north is here minus 3. The south is here plus 3. Set leftnow to left. Set stepsnow to steps. If file is more than 0, Probe from west. If file is less than 2, Probe from east. If band is more than 0, Probe from north. If band is less than 4, Probe from south.

Show answer.

Open in Playground Browse all 1,000 problems

Expected stdout

6