def p_still_in_s(s: str, p: str, removable: list[int], chars_removed: int) -> bool: removed = set(removable[:chars_removed]) p_index = 0 for i, char in enumerate(s): if i in removed: continue if p_index < len(p) and char == p[p_index]: p_index += 1 return p_index == len(p) class Solution: def maximumRemovals(self, s: str, p: str, removable: list[int]) -> int: lo, hi = 0, len(removable) while lo < hi: chars_removed = (lo + hi + 1) // 2 if p_still_in_s(s, p, removable, chars_removed): lo = chars_removed else: hi = chars_removed - 1 return lo