text and pattern, where pattern is a subsequence of text: it can be obtained by crossing out some characters of text without reordering the rest. You also get an array order of distinct indices into text (0-based).
Characters are crossed out one by one in the order of the array: first text[order[0]], then text[order[1]], and so on. The indices always refer to the original string.
Return the largest k (from 0 to len(order)) such that after crossing out the first k characters listed in order, pattern is still a subsequence.text='banana', pattern='ban', order=[5, 1, 0, 3] → 2
After removing positions 5 and 1 we are left with "bnan", which still has b, a, n in order. The third removal takes away the only "b".
text='abcab', pattern='ab', order=[0, 1, 2] → 3
Even after all three removals, "ab" is left.
text='xyz', pattern='xz', order=[2, 1] → 0
The very first removal deletes "z", so nothing can be removed.
order[i] are distincttext and pattern consist of lowercase English letterspattern is a subsequence of texttext='banana', pattern='ban', order=[5, 1, 0, 3]
2
Run checks the first 3 tests in your browser. Submit checks all 63 tests on the server, hidden ones included.