---
# System prepended metadata

title: 2810. Faulty Keyboard
tags: [Leetcode, Easy, String]

---

Link: https://leetcode.com/problems/faulty-keyboard/description/
## Code
```python=
class Solution:
    def finalString(self, s: str) -> str:
        flipped = False
        ans = deque()
        for ch in s:
            if ch == 'i':
                flipped = not flipped
            elif flipped:
                ans.appendleft(ch)
            else:
                ans.append(ch)
        if flipped:
            return "".join(ans)[::-1]
        else:
            return "".join(ans)
```