The TransCompilator

Solved LeetCode program · 140 of 1,000

#0140 · Word Break II

Hard Array chunk-03.md

Original English source

Keep a shared text as empty text. Keep a shared words as an empty list of text. Keep a shared lengths as an empty list of whole numbers. Keep a shared path as an empty list of text. Keep a shared answers as an empty list of text. Keep a shared textsize of 0. Place "catsanddog" into text. Place "cats" into words. Place "cat" into words. Place "and" into words. Place "sand" into words. Place "dog" into words. Place 4 into lengths. Place 3 into lengths. Place 3 into lengths. Place 4 into lengths. Place 3 into lengths. Set textsize to 10.
To store answer. The line is join path with " ". Place line into answers.

To try from start (a whole number) with spot (a whole number). If start is textsize, store answer, return. If spot is more than 4, return. The size is item spot of lengths. If start plus size is more than textsize, try from start with spot plus 1, return. The finish is start plus size. The piece is the slice of text from start to finish. If piece does not match item spot of words, try from start with spot plus 1, return. Place item spot of words into path. Try from finish with 0. Remove the last item from path. Try from start with spot plus 1.

Try from 0 with 0. For each answer in answers, show answer.

Open in Playground Browse all 1,000 problems

Expected stdout

cats and dog
cat sand dog