The TransCompilator

Solved LeetCode program · 958 of 1,000

#1326 · Minimum Number of Taps to Open to Water a Garden

Hard Array chunk-20.md

Original English source

Keep a shared ranges as an empty list of whole numbers. Keep a shared reach as an empty list of whole numbers. Keep a shared nextedge of 0. Place 3 into ranges. Place 4 into ranges. Place 1 into ranges. Place 1 into ranges. Place 0 into ranges. Place 0 into ranges. For every spot from 0 to 5, Place 0 into reach.

To offer from tap (a whole number). The span is item tap of ranges. The start is the larger of tap minus span and 0. The finish is the smaller of tap plus span and 5. If finish is more than item start of reach, Set item start of reach to finish.

To grow from low (a whole number) with high (a whole number). Set nextedge to 0.
For every spot from low to high.
The here is item spot of reach. If here is more than nextedge, set nextedge to here.

For every tap from 0 to 5, Offer from tap. The taps is 0. The edge is 0. The low is 0.
Repeat while edge is less than 5.
Grow from low with edge. If nextedge is more than edge, Add 1 to taps, Set low to edge plus 1, Set edge to nextedge, otherwise Set taps to -1, stop.

If taps is at least 0, Show taps.

Open in Playground Browse all 1,000 problems

Expected stdout

1