The TransCompilator

Solved LeetCode program · 946 of 1,000

#1312 · Minimum Insertion Steps to Make a String Palindrome

Hard String chunk-19.md

Original English source

Keep a shared text as empty text. Keep a shared seeds as an empty list of text. Keep a shared table as an empty list of whole numbers. Place "mbadm" into seeds. Set text to item 0 of seeds. For every cell from 0 to 24, Place 0 into table.

To fill from start (a whole number) with finish (a whole number) and length (a whole number). If length is 1, Set item (start times 5 plus finish) of table to 1, otherwise Extend from start with finish.

To extend from start (a whole number) with finish (a whole number). The here is start times 5 plus finish. The inner is (start plus 1) times 5 plus finish minus 1. The down is (start plus 1) times 5 plus finish. The left is start times 5 plus finish minus 1. The first is character start of text. The second is character finish of text. The best is the larger of item down of table and item left of table. If first is second, Set item here of table to item inner of table plus 2, otherwise Set item here of table to best.

To row from start (a whole number).
For every length from 1 to 5 minus start.
The finish is start plus length minus 1. Fill from start with finish and length.

The start is 4.
Repeat while start is at least 0.
Row from start. Decrease start by 1.

Show 5 minus item 4 of table.

Open in Playground Browse all 1,000 problems

Expected stdout

2