Skip to content

Commit

Permalink
Create 10. Maximum Number of Removable Characters.py
Browse files Browse the repository at this point in the history
  • Loading branch information
SamirPaulb authored Jan 31, 2023
1 parent 3781489 commit 1432446
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions 11_Binary-Search/10. Maximum Number of Removable Characters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# https://leetcode.com/problems/maximum-number-of-removable-characters/

class Solution:
def maximumRemovals(self, s: str, p: str, removable: List[int]) -> int:
def isSubsequence(mid):
remove = set(removable[:mid+1])
i = j = 0
while i < len(s) and j < len(p):
if s[i] == p[j] and i not in remove:
j += 1
i += 1
return j == len(p)


res = 0
l, r = 0, len(removable)-1
while l <= r:
mid = l + (r - l)//2
if isSubsequence(mid):
res = max(res, mid+1)
l = mid + 1
else:
r = mid - 1

return res


# Time: (n * log(k)) # n = len(s), k = len(removable)

0 comments on commit 1432446

Please sign in to comment.