Given a 0-indexed string word and a character ch, reverse the segment of word that starts at index 0 and ends at the index of the first occurrence of ch (inclusive). If ch does not occur in word, return word unchanged. Return the resulting string.
Given a 0-indexed string word and a character ch, reverse the segment of word that starts at index 0 and ends at the index of the first occurrence of ch (inclusive). If ch does not occur in word, return word unchanged. Return the resulting string.
Example 1:
Input: {"word":"abcdefd","ch":"d"}
Output: dcbaefd
Constraints:
1≤word.length≤250
word consists of lowercase English letters.
ch is a lowercase English letter.
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"word":"abcdefd","ch":"d"}
Look for the first 'd' in "abcdefd". Everything up to and including it is the prefix to reverse.