The TransCompilator

Solved LeetCode program · 965 of 1,000

#1334 · Find the City With the Smallest Number of Neighbors at a Threshold Distance

Medium Dynamic Programming chunk-20.md

Original English source

The cities is 4, while the limit is 4. The links is a list of 0, 1, 3, 1, 2, 1, 1, 3, 4, 2, 3, and 1. The distance is a list of 16 zeros.
For every spot from 0 to 15.
Set item spot of distance to 1000000.
For every city from 0 to 3.
Set item (city times 4 plus city) of distance to 0.
For every link from 0 to 3.
The start is item (link times 3) of links. The finish is item (link times 3 plus 1) of links. The weight is item (link times 3 plus 2) of links. Set item (start times 4 plus finish) of distance to weight. Set item (finish times 4 plus start) of distance to weight.

For every middle from 0 to 3.
For every start from 0 to 3.
For every finish from 0 to 3.
The through is item (start times 4 plus middle) of distance plus item (middle times 4 plus finish) of distance. If through is less than item (start times 4 plus finish) of distance, set item (start times 4 plus finish) of distance to through.

The chosen is -1, while the fewest is 1000000.
For every city from 0 to 3.
The reach is 0.
For every other from 0 to 3.
If city is not other and item (city times 4 plus other) of distance is at most limit, add 1 to reach. If reach is at most fewest, set fewest to reach, set chosen to city.

Show chosen.

Open in Playground Browse all 1,000 problems

Expected stdout

3