The TransCompilator

Solved LeetCode program · 389 of 1,000

#0522 · Longest Uncommon Subsequence II

Medium Array chunk-08.md

Original English source

Keep a shared words holding "aba", "cdc", and "eae". Keep a shared count of 3. Keep a shared source as empty text. Keep a shared target as empty text. Keep a shared current 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.

To evaluate with first (a whole number). Set current to item first of words. Measure. If span is more than best, set best to span.

To probe from first (a whole number) with second (a whole number). If second is at least count, evaluate with first, return. If second is first, probe from first with second plus 1, return. Set source to item first of words. Set target to item second of words. Set found to 0. Scan from 0 with 0. If found is 1, return. Probe from first with second plus 1.

For every first from 0 to count minus 1.
Probe from first with 0.

Show best.

Open in Playground Browse all 1,000 problems

Expected stdout

3