An intercepted transmission is recorded as a single lowercase string s. Analysts also hold a list of k short suspected fragment codes. A fragment code is considered contained in the transmission if it appears as a contiguous run of characters somewhere inside s. Count how many of the k fragment codes are contained in the transmission.
Print a single integer: the number of fragment codes that occur as a contiguous substring of s.
Example 1
Input
beacon 4 bea con xyz aco
Expected
3
Explanation
s = "beacon". "bea" matches the first three letters, "con" matches the last three letters, "xyz" never appears, and "aco" matches the middle letters (positions 2-4: a,c,o). So 3 of the 4 fragments are contained.
Example 2
Input
signal 4 sig nal sn al
Expected
3
Explanation
s = "signal". "sig" matches the first three letters, "nal" matches the last three letters, "al" matches the last two letters, but "sn" never appears contiguously since the 's' at index 0 is followed by 'i', not 'n'. So 3 of the 4 fragments are contained.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →