FunctionRacerProblemsRace

Prefix of Any Word in a Sentence

BeginnerStringsPython, JavaScript, TypeScript, Java, C++

Words in sentence are separated by single spaces and numbered from 1. Return the number of the first word that starts with searchWord, or -1 if no word does.

Example 1

sentence "i love eating burger"
searchWord "burg"
returns 4

burger is word 4.

Example 2

sentence "this problem is an easy problem"
searchWord "pro"
returns 2

The first match is word 2.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Strings problems