Trains the technique from
LeetCode 1312Minimum Insertion Steps to Make a String PalindromeThis 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 mosaic strip is written as strip, one lowercase letter per tile, read left to right. Each letter names a tile colour.
In one step you may buy a tile of any colour and slide it into the strip at any position: in front of the first tile, between two neighbouring tiles, or after the last tile. Tiles already on the strip are never removed and never change their order.
A strip is mirrored when the colours read from left to right are the same as the colours read from right to left.
Return the fewest steps needed to leave the strip mirrored.
Example 1
Buying five tiles gives `tlabocobalt`, which reads the same in both directions and keeps the six original tiles in their original order.
Example 2
One bought tile is enough: sliding a `b` in front gives `baaab`, which reads the same both ways.
Example 3
This strip already reads the same in both directions, so no tile is bought.
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 fewest_inserts(strip: str) -> int:public int fewestInserts(String strip)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.