Number of Strings That Appear as Substrings in Word - Problem
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.
Input & Output
Example 1 — Basic Case
$
Input:
patterns = ["a","aa","aaa"], word = "aaaa"
›
Output:
3
💡 Note:
All patterns are substrings: "a" appears at positions 0,1,2,3; "aa" appears at positions 0,1,2; "aaa" appears at positions 0,1
Example 2 — Partial Matches
$
Input:
patterns = ["a","b","c"], word = "aaaaabbbbb"
›
Output:
2
💡 Note:
"a" and "b" are found in word, but "c" is not present
Example 3 — No Matches
$
Input:
patterns = ["a","a","a"], word = "ab"
›
Output:
3
💡 Note:
All three patterns "a" exist in word "ab", even though they're duplicates
Constraints
- 1 ≤ patterns.length ≤ 100
- 1 ≤ patterns[i].length ≤ 100
- 1 ≤ word.length ≤ 100
- patterns[i] and word consist of lowercase English letters.
Visualization
Tap to expand
Understanding the Visualization
1
Input
Array of patterns and target word
2
Process
Check each pattern as substring in word
3
Output
Count of patterns found
Key Takeaway
🎯 Key Insight: Use built-in substring methods to efficiently count pattern occurrences
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code