Solved LeetCode program · 861 of 1,000
#1162 · As Far from Land as Possible
Original English source
Keep a shared active of 0. Keep a shared size of 3. The lands is a list of 1, 0, 1, 0, 0, 0, 1, 0, and 1. Keep a shared distances as an empty list of whole numbers. For every cell from 0 to 8, Place -1 into distances. Keep a shared queue as an empty list of whole numbers. Keep a shared count of 0.
For every cell from 0 to 8.
If item cell of lands is 1, set item cell of distances to 0, Place cell into queue, add 1 to count.
To relax with target (a whole number). The here is active. If item target of distances is at least 0, return. Set item target of distances to item here of distances plus 1. Place target into queue. Add 1 to count.
To spread. The band is active divided by size. The column is active modulo size. If band is more than 0, Relax with active minus size. If band is less than size minus 1, Relax with active plus size. If column is more than 0, Relax with active minus 1. If column is less than size minus 1, Relax with active plus 1.
The head is 0.
Repeat while head is less than count.
The front is head. Set active to item front of queue. Add 1 to head. Spread.
The best is -1.
For every cell from 0 to 8.
If item cell of distances is more than best, set best to item cell of distances.
If best is 0, show -1, otherwise show best.
Expected stdout
2