The TransCompilator

Solved LeetCode program · 391 of 1,000

#0524 · Longest Word in Dictionary through Deleting

Medium Array chunk-08.md

Original English source

Keep a shared words holding "ale", "apple", "monkey", and "plea". Keep a shared source as empty text. Keep a shared target as empty text. The longsource is "abpcplea". The copy is a copy of longsource. Set target to copy. Keep a shared current as empty text. Keep a shared winner as empty text. Keep a shared found of 0. Keep a shared span of 0. Keep a shared best of 0.

To scan from through (a whole number) with aim (a whole number). If aim is more than the last position of source, set found to 1, return. If through is more than the last position of target, return. If the slice of target from through to through plus 1 matches the slice of source from aim to aim plus 1, scan from through plus 1 with aim plus 1, return. Scan from through plus 1 with aim.

To measure. Set span to 0.
For every spot from 0 to the last position of current.
Add 1 to span.

For each word in words.
Set source to word. Set found to 0. Scan from 0 with 0. If found is 1, set current to word. If found is 1, measure. If found is 1 and span is more than best, set best to span, set winner to current. If found is 1 and span is best, If the length of winner is more than 0, If current comes before winner, set winner to current.

Show winner.

Open in Playground Browse all 1,000 problems

Expected stdout

apple