left
to 0 and right
to the length of the removable
array.left
is less than or equal to right
:
a. Calculate mid
as the average of left
and right
.
b. Mark the characters at indices removable[0]
to removable[mid - 1]
in s
as removed.
c. Check if p
is still a subsequence of the modified s
.
d. If p
is a subsequence, set left
to mid + 1
(try a higher k
).
e. If p
is not a subsequence, set right
to mid - 1
(try a lower k
).right
as the maximum k
.