
overlapped
Given a string s
and a dictionary d
, find the number of pairs of words from the dictionary, whose occurrences in s
overlap. Note, that two words can overlap more than once, and a word may overlap itself.
Example
-
For
s = "knowledgeneralhellohellotestcase"
andd = "knowledge", "general", "hello"],
the output should beoverlapped(s, d) = 1
.In this example,
"knowledge"
and"general"
overlaps. -
For
s = "iloveprogrammingenuityweneededginess"
andd = ["programming", "ingenuity", "needed", "edginess"],
the output should beoverlapped(s, d) = 2
.Here,
"programming"
overlaps with"ingenuity"
and"needed"
overlaps with"edginess"
.
Input/Output
-
[execution time limit] 0.5 seconds
-
[input] string s
A string of lowercase English letters.
Constraints:
3 ≤ s.length ≤ 150
. -
[input] array.string d
List of distinct words, where each word consists of lowercase English letters.
Constraints:
1 ≤ d.length ≤ 15
,1 ≤ d[i] ≤ 15
. -
[output] integer
- The number of pairs of words that overlap.
Post Comment