The TransCompilator

Solved LeetCode program · 914 of 1,000

#1268 · Search Suggestions System

Medium Array chunk-19.md

Original English source

Keep a shared wordslist holding "mobile", "moneypot", "monitor", "mouse", and "mousepad".
For every left from 0 to 4.
For every right from left plus 1 to 4.
If item right of wordslist comes before item left of wordslist, swap item left of wordslist and item right of wordslist.

Keep a shared pickscount of 0. Keep a shared opening as empty text. Keep a shared line as empty text. Keep a shared same of 0.

To match from index (a whole number). Set same to 1. The word is item index of wordslist. The span is the length of opening.
For every part from 0 to span minus 1.
If character part of word is not character part of opening, set same to 0.

To collect. Set line to empty text. Set pickscount to 0.
For every index from 0 to the last position of wordslist.
The word is item index of wordslist.
If pickscount is less than 3.
If the length of word is at least the length of opening.
Match from index.
If same is 1.
If pickscount is more than 0, Place "," into line. Place word into line. Add 1 to pickscount.

The sought is "mouse".
For every spot from 0 to the last position of sought.
The piece is the slice of sought from spot to spot plus 1. Place piece into opening. Collect. Show line.

Open in Playground Browse all 1,000 problems

Expected stdout

mobile,moneypot,monitor
mobile,moneypot,monitor
mouse,mousepad
mouse,mousepad
mouse,mousepad