text, a string pattern that is a subsequence of text, and an increasing list marked of distinct indices into text.
An editor lets you erase letters only at marked positions, one at a time, and only as long as pattern is still a subsequence of the text after each erasure. An erased letter leaves a gap: the other letters keep their indices.
Return the largest number of letters you can erase.
A string p is a subsequence of t if p can be obtained from t by deleting some characters without changing the order of the rest.text='banana', pattern='ban', marked=[1, 2, 3, 5] → 3
Erase positions 1 and 2: "b__ana" still spells "ban" through b, the a at 3 and the n at 4. Position 3 cannot go as well, since the only a left after b would be at 5, with no n after it. Position 5 can always be erased. That makes 3.
text='code', pattern='code', marked=[0, 3] → 0
The pattern is the whole text, so not a single letter can go.
text='xaxbx', pattern='ab', marked=[0, 2, 4] → 3
Every marked position holds an x the pattern never needs, so all of them can be erased.
marked is strictly increasing, 0 ≤ marked[i] < len(text)text and pattern contain only lowercase English letterspattern is a subsequence of texttext='banana', pattern='ban', marked=[1, 2, 3, 5]
3
Run checks the first 3 tests in your browser. Submit checks all 72 tests on the server, hidden ones included.