Trains the technique from
LeetCode 1717Maximum Score From Removing SubstringsThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A tape tape holds lowercase letters. Two moves are allowed, each usable as often as the pattern shows up:
ab and collect x points.ba and collect y points.Pulling a pair out closes the gap, so letters that were apart may become neighbours.
Return the most points that can be collected.
Example 1
Only one pull is ever possible. Taking ba from the back pays 5, while taking ab from the front would pay 1.
Example 2
The only pair on offer reads ba and pays 1. Once it is gone the tape reads bb with nothing left to pull.
Example 3
The c splits the tape in two. On the left ab pays 5 and on the right ba pays 1.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def maximum_gain(tape: str, x: int, y: int) -> int:public int maximumGain(String tape, int x, int y)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.