Prefix of Any Word in a Sentence
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
1 <= len(sentence) <= 1001 <= len(searchWord) <= 10- Lowercase letters and single spaces
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Strings problems
- Remove Vowels from a StringBeginner
- Reverse Each WordBeginner
- Reverse Prefix of WordBeginner
- Reverse StringBeginner
- Snake Case to Camel CaseBeginner
- Stretch Each CharacterBeginner
- Student Attendance RecordBeginner
- Sum of Digits in TextBeginner