The TransCompilator

Solved LeetCode program · 872 of 1,000

#1187 · Make Array Strictly Increasing

Hard Array chunk-18.md

Original English source

Keep a shared firsts holding 1, 5, 3, 6, and 7.

Keep a shared seconds holding 1, 3, 2, and 4.

Keep a shared ways as an empty list of whole numbers.
For every spot from 0 to 24.
Place 999 into ways.

Keep a shared best of 0.

To relax from row (a whole number) with option (a whole number). Set best to 999. The value is item row of firsts. If option is more than 0, set value to item (option minus 1) of seconds. The previous is row minus 1.
For every prior from 0 to 4.
The old is item (previous times 5 plus prior) of ways. The before is item previous of firsts. If prior is more than 0, set before to item (prior minus 1) of seconds. If old is less than best and before is less than value, set best to old.

Set item 0 of ways to 0. Set item 1 of ways to 1. Set item 2 of ways to 1. Set item 3 of ways to 1. Set item 4 of ways to 1.

For every row from 1 to 4.
For every option from 0 to 4.
Relax from row with option. The cost is best. If option is more than 0, add 1 to cost. Set item (row times 5 plus option) of ways to cost.

The answer is 999.
For every option from 0 to 4.
If item (20 plus option) of ways is less than answer, set answer to item (20 plus option) of ways.

If answer is at least 999, show -1, otherwise show answer.

Open in Playground Browse all 1,000 problems

Expected stdout

1