-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmaximum-number-of-removable-characters.cpp
45 lines (37 loc) · 1.22 KB
/
maximum-number-of-removable-characters.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
class Solution {
public:
int maximumRemovals(string s, string p, vector<int>& removable) {
function<bool(string)> isSubsequence = [&] (string fullText) -> bool {
int match = 0;
for(int i = 0; i< fullText.size(); i++) {
if (fullText[i] == p[match] ) {
match++;
}
}
return match == p.size();
};
function<bool(int)> check = [=](int mid) -> bool {
cout<<mid<<endl;
string processedStr = s;
for(int i=0; i< mid; i++) {
processedStr[removable[i]] = '.';
}
return isSubsequence(processedStr);
};
function<int()> binarySearchPortion = [&]() -> int {
int left = 0;
int right = removable.size();
int mid;
while(left <= right) {
mid = (left + right) >> 1;
if (check(mid)) {
left = mid + 1;
} else {
right = mid - 1;
}
}
return right;
};
return binarySearchPortion();
}
};