Number of Strings That Appear as Substrings in Word

Given an array of strings `patterns` and a string `word`, return the **number** of strings in `patterns` that exist as a **substring** in `word`. A **substring** is a contiguous sequence of characters within a string.

30:00

Number of Strings That Appear as Substrings in Word
easy
Free written solution
Topics
Companies

Given an array of strings patterns and a string word, return the number of strings in patterns that exist as a substring in word. A substring is a contiguous sequence of characters within a string.

Example 1:
Input: {"patterns":["a","abc","bc","d"],"word":"abc"}
Output: 3
Constraints:
  • 1≤patterns.length≤1001 \leq \text{patterns.length} \leq 100

  • 1≤patterns[i].length≤1001 \leq \text{patterns}[i]\text{.length} \leq 100

  • 1≤word.length≤1001 \leq \text{word.length} \leq 100

  • patterns[i] and word consist of lowercase English letters.

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"patterns":["a","abc","bc","d"],"word":"abc"}

Test each of the 4 patterns against "abc". Slide it along the word; if it lines up somewhere, count it.

word on top, the current pattern as a stencil below it

a
b
c
0
1
2

patterns

a
abc
bc
d

count = 0 / 4

Variables
VariableValue
count0
DepthFunction Call
Stack empty
0/13