3
bool isSubSequence(string str1, string str2) {4
int j = 0, m = str1.size(), n = str2.size();5
for (int i = 0; i < n && j < m; i++)6
if (str1[j] == str2[i]) j++;9
int maximumRemovals(string s, string p, vector<int> &removable) {11
int left = 0, right = removable.size();12
while (left <= right) {13
int mid = (left + right) / 2;14
for (int i = 0; i < mid; i++) copy[removable[i]] = '*';15
if (isSubSequence(p, copy))16
// if p is subsequence of string after mid number of removals then we17
// should look for if it's possible to remove more characters20
// if p is not a subsequence of string it means that we have certainly21
// removed more characters from string so we must decrease our size of22
// removal characters and hence we add all characters we removed24
for (int i = 0; i < mid; i++) copy[removable[i]] = s[removable[i]];