Trains the technique from
LeetCode 647Palindromic 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 label printer has run off a tape of lowercase letters, handed to you as the string tape. Quality control wants to know how much of the tape reads the same whichever way you feed it into the reader.
A stretch is one or more neighbouring letters of the tape, pinned down by where it starts and where it ends. A stretch is reversible when its letters spell out the same thing read right to left as they do read left to right. A stretch of a single letter is reversible.
Return how many reversible stretches the tape holds. Stretches that cover different positions count separately, even when they spell the same letters, so the tape "dd" holds three: each d on its own, plus the pair.
Example 1
The three single letters are reversible, and so is the whole tape.
Example 2
Four single letters, then `qq`, then the whole tape, and nothing else reads the same both ways.
Example 3
No two neighbouring letters match, so only the four single letters are reversible.
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 count_reversible_stretches(tape: str) -> int:public int countReversibleStretches(String tape)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.