Practice Maximum Number of Removable Characters
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Maximum Number of Removable Characters
Problem Statement
You are given two strings s and p where p is a subsequence of s. You are also given a distinct 0-indexed integer array removable containing a subset of indices of s (s is also 0-indexed). You want to choose an integer k (0 <= k <= removable.length) such that, after removing k characters from s using the first k indices in removable, p is still a subsequence of s. More formally, you will mark the character at s[removable[i]] for each 0 <= i < k, then remove all marked characters and check if p is still a subsequence. Return the maximum k you can choose such that p is still a subsequence of s after the removals. A subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters.
Source: Maximum Number of Removable Characters on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
s = "abcacb", p = "ab", removable = [3,1,0]
2
# Example 2
s = "abcbddddd", p = "abcd", removable = [3,2,1,4,5,6]
1
# Example 3
s = "abcab", p = "abc", removable = [0,1,2,3,4]
0
Constraints
Related LeetCode Problems
Practice more problems similar to Maximum Number of Removable Characters.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.