The TransCompilator

Solved LeetCode program · 816 of 1,000

#1061 · Lexicographically Smallest Equivalent String

Medium String chunk-17.md

Original English source

Keep a shared alphabet as empty text. Keep a shared targetcode of 0. Keep a shared rankresult of 0. Keep a shared parents as an empty list of whole numbers. Keep a shared rootletter of 0.

To rank.
For every probe from 0 to 25.
If character probe of alphabet is targetcode, set rankresult to probe, return.

To seek from letter (a whole number). If item letter of parents is letter, set rootletter to letter, return. Seek from item letter of parents.

The letters is "abcdefghijklmnopqrstuvwxyz". The frozen is a copy of letters. Set alphabet to frozen.
For every spot from 0 to 25.
Place spot into parents.

The first is "parker". The second is "morris". The base is "parser".
For every spot from 0 to the last position of first.
Set targetcode to character spot of first. Rank. The left is rankresult. Set targetcode to character spot of second. Rank. The right is rankresult. Seek from left. The firstroot is rootletter. Seek from right. The secondroot is rootletter. If firstroot is less than secondroot, set item secondroot of parents to firstroot. If secondroot is less than firstroot, set item firstroot of parents to secondroot.

The answer is empty text.
For every spot from 0 to the last position of base.
Set targetcode to character spot of base. Rank. Seek from rankresult. The place is rootletter. The mapped is character place of alphabet. Place mapped into answer.

Show answer.

Open in Playground Browse all 1,000 problems

Expected stdout

makkek