Trains the technique from
LeetCode 28Find the Index of the First Occurrence in a StringThis 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.
Every crate in a depot is stencilled with a long identifier, given as the lowercase string label. A conveyor belt decides where a crate goes by hunting for a short routing marker inside that identifier, given as the lowercase string tag.
Return the smallest index i such that the len(tag) consecutive characters of label starting at position i spell tag exactly. If the marker is nowhere inside the identifier, return -1.
Both strings are non-empty, and the marker may well be longer than the identifier.
Example 1
Characters 4 through 6 of the identifier spell the marker; nothing earlier does.
Example 2
A shorter partial match begins at position 1 and dies at the fourth character, so the answer is the later position 4 where all five characters line up.
Example 3
The three characters never sit next to each other in that arrangement.
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 locate_tag(label: str, tag: str) -> int:public int locateTag(String label, String tag)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.