Ctrl K

Flip Up to a Letter

Easy
You are given a word word and a letter letter. Find the first occurrence of letter in the word and reverse the part from the start of the word up to and including that letter. Everything after it stays as is. If letter does not occur in the word, return the word unchanged.
Example 1
word='planet', letter='n' → 'nalpet'

The first n is at index 3. The head plan turns into nalp and the tail et stays: nalpet.

Example 2
word='banana', letter='a' → 'abnana'

Only the first a (index 1) matters: ba becomes ab and the rest is untouched, giving abnana.

Example 3
word='river', letter='x' → 'river'

There is no x in the word, so it comes back unchanged.

Constraints
  • 1 ≤ word.length ≤ 250
  • word consists of lowercase English letters
  • letter is a single lowercase English letter
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsSame Text After Erasing EasySwapping Brackets Into Balance MediumBracket Balance EasyWhere the Fragment Starts EasyMirror Phrase Check Easy
loading Python…
Input
word='planet', letter='n'
Expected
'nalpet'

Run checks the first 3 tests in your browser. Submit checks all 135 tests on the server, hidden ones included.