text and word made of lowercase English letters. You may add any letters to the end of text.
Find the fewest letters you must add so that word becomes a subsequence of the result: it can be read in it from left to right, possibly skipping other letters in between.text="planet", word="plane" → 0
The letters p, l, a, n, e already appear in text in the right order, so nothing needs to be added.
text="banana", word="bandana" → 4
Only "ban" can be taken from text, because no d follows that n. Appending "dana" gives "bananadana", where "bandana" reads as b, a, n from the start and d, a, n, a from the tail.
text="xyz", word="cab" → 3
text has no c at all, so the whole word has to be appended.
text and word contain only lowercase English letterstext="planet", word="plane"
0
Run checks the first 3 tests in your browser. Submit checks all 149 tests on the server, hidden ones included.