#1898
Maximum Number of Removable Characters
specialist · 925 · lc medium +32 · verified · 46.9% accepted · 1,049 likes · top 31%
Description
Given strings s and p where p is a subsequence of s, and a distinct 0-indexed integer array removable, find the maximum k such that after removing characters of s at indices removable[0] through removable[k-1], p remains a subsequence of the modified s.
Return that maximum k.
Example 1:
Input: s = "abcacb", p = "ab", removable = [3,1,0]
Output: 2
Explanation: After removing the characters at indices 3 and 1, "abcacb" becomes "accb".
"ab" is a subsequence of "accb".
If we remove the characters at indices 3, 1, and 0, "abcacb" becomes "ccb", and "ab" is no longer a subsequence.
Hence, the maximum k is 2.
Example 2:
Input: s = "abcbddddd", p = "abcd", removable = [3,2,1,4,5,6]
Output: 1
Explanation: After removing the character at index 3, "abcbddddd" becomes "abcddddd".
"abcd" is a subsequence of "abcddddd".
Example 3:
Input: s = "abcab", p = "abc", removable = [0,1,2,3,4]
Output: 0
Explanation: If you remove the first index in the array removable, "abc" is no longer a subsequence.
Code
1
2
3