Faulty Keyboard

Your laptop keyboard is faulty, and whenever you type a character 'i' on it, it reverses the string that you have written. Typing other characters works as expected.

You are given a 0-indexed string s, and you type each character of s using your faulty keyboard.

Return the final string that will be present on your laptop screen.

Example 1
Inputs = "string"
Output"rtsng"
Typing characters from s builds str, the fourth character 'i' reverses it to rts, and the remaining characters produce rtsng.
Example 2
Inputs = "poiinter"
Output"ponter"
The two consecutive 'i' characters reverse the current text twice, returning it to po, and the remaining characters produce ponter.

Constraints

  • 1 <= s.length <= 100
  • s consists of lowercase English letters.
  • s[0] != 'i'

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate