Trains the technique from
LeetCode 1967Number of Strings That Appear as Substrings in WordThis 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 produced one long strip of lowercase letters, given as strip. A picking sheet lists short product codes in codes, each also made of lowercase letters.
A code is printed on the strip when its letters occur in the strip next to each other and in the same order, that is, when the code is exactly some run of consecutive letters of the strip.
Return how many entries of codes are printed on the strip. The sheet may list the same code more than once, and each entry counts on its own.
Example 1
The letters `ab` sit next to each other in the strip at offset 1, and the sheet lists that code twice, so it contributes two. The strip holds no `z` at all.
Example 2
`kite`, `ki`, `ite` and `kit` each appear as a run of consecutive letters of the strip. `tie` does not: the strip has a `t`, an `i` and an `e`, but never in that order side by side.
Example 3
The strip holds both an `a` and a `c`, but a `b` stands between them, so the code is not a run of consecutive letters of the strip.
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 codes_on_strip(codes: list[str], strip: str) -> int:public int codesOnStrip(String[] codes, String strip)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.