The TransCompilator

Solved LeetCode program · 351 of 1,000

#0475 · Heaters

Medium Array chunk-08.md

Original English source

Keep a shared heaters as an empty list of whole numbers. Place 2 into heaters. Keep a shared nearest of 0. Keep a shared gap of 0.
To score with house (a whole number). Set nearest to 1000000.
For each heater in heaters.
Set gap to house minus heater. Set gap to the absolute value of gap. If gap is less than nearest, set nearest to gap.

The houses is a list of 1, 2, 3. The far is 0.
For each house in houses.
Score with house. If nearest is more than far, set far to nearest.

Show far.

Open in Playground Browse all 1,000 problems

Expected stdout

1