Show problems as
Classic problem #1967EasyArrayString

Number of Strings That Appear as Substrings in Word

Real-world version: Codes Printed On The Label Strip
Tracked in this browser only
Read Number of Strings That Appear as Substrings in Word on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

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.

Examples

Example 1

Input
codes = ["ab", "ab", "zz"], strip = "cabd"
Output
2

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

Input
codes = ["kite", "ki", "ite", "kit", "tie"], strip = "spikite"
Output
4

`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

Input
codes = ["ac"], strip = "abc"
Output
0

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.

Constraints

  • 1 <= codes.length <= 100
  • 1 <= codes[i].length <= 100
  • 1 <= strip.length <= 100
  • codes[i] and strip hold lowercase English letters only.

The signature

The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

Python
def codes_on_strip(codes: list[str], strip: str) -> int:
Java
public int codesOnStrip(String[] codes, String strip)