A regional dispatch centre keeps its radio traffic as a single line of lowercase words separated by single spaces (a "transcript"). A supervisor wants to jump straight to the first word in the transcript that begins with a given callsign prefix. Given the transcript and the prefix, report the 1-indexed position of the first word whose leading letters exactly match the prefix. If no word qualifies, report -1.
Print a single integer: the 1-indexed position of the first word in the transcript that has the prefix as its prefix, or -1 if no word qualifies.
Example 1
Input
i love eating burger burg
Expected
4
Explanation
The words are "i", "love", "eating", "burger". None of the first three words start with "burg", but the 4th word "burger" does, so the answer is 4.
Example 2
Input
this problem is an easy problem pro
Expected
2
Explanation
The words are "this", "problem", "is", "an", "easy", "problem". The 2nd word "problem" is the first word that starts with "pro", so the answer is 2.
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 →