The TransCompilator

Solved LeetCode program · 879 of 1,000

#1202 · Smallest String With Swaps

Medium Array chunk-18.md

Original English source

Keep a shared source as empty text. Place "dcab" into source. Keep a shared parent as an empty list of whole numbers. Keep a shared groups as an empty list of text. Keep a shared taken as an empty list of whole numbers. Keep a shared result as empty text. Keep a shared root of 0.

The size is 4.
For every spot from 0 to size minus 1.
Place spot into parent. Place "" into groups. Place 0 into taken.

To locate from spot (a whole number). Set root to spot. The cursor is spot.
Repeat while item cursor of parent is not cursor.
Set cursor to item cursor of parent. Set root to cursor.

To gather from spot (a whole number). Locate from spot. The place is root. The piece is the slice of source from spot to spot plus 1. The current is item place of groups. Place piece into current. Set item place of groups to current.

To pick from spot (a whole number). Locate from spot. The place is root. The start is item place of taken. The upper is start plus 1. The block is item place of groups. The piece is the slice of block from start to upper. Place piece into result. Set item place of taken to upper.

The pairs is a list of 0, 3, 1, and 2.
For every pair from 0 to 1.
The one is item (pair times 2) of pairs. The two is item (pair times 2 plus 1) of pairs. Locate from one. The firstroot is root. Locate from two. The secondroot is root. If firstroot is not secondroot, set item firstroot of parent to secondroot.

For every spot from 0 to size minus 1.
Gather from spot.

For every spot from 0 to size minus 1.
The current is item spot of groups. The ordered is sort characters of current. Set item spot of groups to ordered.

For every spot from 0 to size minus 1.
Pick from spot.

Show result.

Open in Playground Browse all 1,000 problems

Expected stdout

bacd