A supply convoy's radio channel logs every word spoken over the net as one long, space-separated transcript. Dispatch analysts want to audit a specific two-word radio cue: whenever the first cue word is immediately followed by the second cue word, the very next word spoken is treated as an echoed instruction that gets flagged for review. Given the full transcript and the two-word cue, output every echoed instruction, in the order its triggering cue occurred in the transcript.
Line 1: the transcript, a sequence of space-separated lowercase words. Line 2: the two-word cue, given as two space-separated lowercase words: first second.
Print the echoed words, separated by single spaces, in the order their triggering cue occurred in the transcript. A word may be echoed more than once if the cue re-occurs, including cues that overlap each other. If the cue is never immediately followed by a third word anywhere in the transcript, print an empty line.
Example 1
Input
alpha bravo charlie alpha bravo delta echo alpha bravo alpha alpha bravo
Expected
charlie delta alpha
Explanation
The cue "alpha bravo" occurs three times: at positions 0-1 (followed by charlie), positions 3-4 (followed by delta), and positions 7-8 (followed by alpha). The trailing "bravo alpha" at positions 8-9 is not a fourth occurrence because the cue itself is "alpha bravo", not "bravo alpha". So the echoed words, in order, are charlie delta alpha.
Example 2
Input
sun moon star moon sun
Expected
(empty)Explanation
The cue "moon sun" never appears as consecutive words in the transcript -- moon is followed by star, not sun -- so there are no echoed words and the program prints an empty line.
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 →