On these texts, the trie walk was about six times faster than the bounded slices
Then measure all three versions on the same texts.
Predict
Double the text, from 1,001 letters to 2,009. About how much longer does can_split_slices take?
The dictionary was the 100,000 words: a set for the two slicing versions, and a trie for can_split. The texts were random words from it glued together, so each one splits.
The three texts come from one rng = random.Random(5), each built with while len(text) < n: text += rng.choice(words) for n of 1,000, then 2,000, then 4,000. The longest word in the sample has 24 letters. Best of 5:
Letters
All slices, ms
Last 24, ms
Trie, ms
1,001
41.1
1.12
0.17
2,009
264.9
2.24
0.36
4,008
1,866.0
4.64
0.77
Doubling the text multiplied the every-start time by 6.4 and then 7.0, on its way to the 8 that O(n³) predicts. The other two double.
The bounded version is a fine answer in an interview. The trie walk was about six times faster here, because it stops early and never builds a string.
The same move turns word search on a grid, the depth-first-search lesson's backtracking question from Netflix's list (1 source), into a search for many words at once. Carry a trie node along the path instead of a position in one word. That's the worked example below.