The TransCompilator

Solved LeetCode program · 974 of 1,000

#1345 · Jump Game IV

Hard Array chunk-20.md

Original English source

The values is a list of 100, -23, -23, 404, 100, 23, 23, 23, 3, and 404. The distances is a list of 10 zeros. The queue is a list of 10 zeros.
For every spot from 0 to 9.
Set item spot of distances to -1. Set item spot of queue to 0.

Set item 0 of distances to 0. Set item 0 of queue to 0. The head is 0, while the count is 1, while the answer is -1.
Repeat while head is less than count and answer is less than 0.
The node is item head of queue. Add 1 to head. If node is 9, set answer to item node of distances, stop.
For every next from 0 to 9.
If item next of distances is less than 0.
The same is 0. If next is node minus 1 or next is node plus 1, set same to 1. If item next of values is item node of values, set same to 1.
If same is 1.
Set item next of distances to item node of distances plus 1. Set item count of queue to next. Add 1 to count.

Show answer.

Open in Playground Browse all 1,000 problems

Expected stdout

3