Reverse Prefix of Word
Find the first place the single character ch appears in word. Return word with the part from the start up to and including that character reversed.
If ch does not appear in word, return word unchanged.
Example 1
word "abcdefd"
ch "d"
returns "dcbaefd"
The first d is at index 3, so abcd becomes dcba: dcbaefd.
Example 2
word "xyz"
ch "a"
returns "xyz"
a is missing, so nothing changes.
Constraints
1 <= len(word) <= 100chis one lowercase letterwordis lowercase letters
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Strings problems
- Reverse StringBeginner
- Snake Case to Camel CaseBeginner
- Stretch Each CharacterBeginner
- Student Attendance RecordBeginner
- Sum of Digits in TextBeginner
- Truncate SentenceBeginner
- Two String Lists Spell the Same WordBeginner
- Vowel and Consonant TallyBeginner