Trains the technique from
LeetCode 1668Maximum Repeating SubstringThis 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 device writes a single line of lowercase letters, given as stream, and a watchdog looks for a marker, given as tag.
The marker is said to run k times when k copies of the whole marker, written one straight after another with nothing in between, appear as a contiguous stretch of stream.
Return the largest k for which that happens. If the marker never appears in the line at all, return 0.
Example 1
Three copies of the marker written together spell "abcabcabc", and that stretch sits in the line starting at position 2.
Example 2
The marker appears at position 0 and again at position 4, but "abab" is nowhere in the line, so the longest run is a single copy.
Example 3
The marker is longer than the line, so not even one copy fits.
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 longest_tag_run(stream: str, tag: str) -> int:public int longestTagRun(String stream, String tag)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.