Find and remove a typo that creates a repeated character in a word.
Problem
You are given a single word. Somewhere in the word, a typo may have occurred: one character was accidentally typed twice in a row.
Your task is to fix the word by removing exactly one character from a consecutive equal pair so that the resulting string matches the intended word.
If there is no such typo, the word should remain unchanged.
What counts as a typo?
A typo is present if there exists an index such that s[i] == s[i+1]. In that case, remove one of these two equal characters in the most appropriate way so the word becomes valid again.
Notes
- The input is a single lowercase word.
- The answer is obtained by deleting one character from a duplicated adjacent pair, if such a pair exists.
- If multiple adjacent equal pairs exist, fix the first one that appears.
Input Format
- A single string consisting of lowercase English letters.
Output Format
- Print the corrected string after fixing the typo, or the original string if no fix is needed.
Constraints
- contains only lowercase English letters.
Example 1
Input
atttachment
Output
atttachment
Explanation
The repeated characters are part of the typo; removing one of the duplicated letters restores the intended word.
Example 2
Input
helllo
Output
hello
Explanation
The first repeated pair is ll, so removing one l fixes the word.
Show 1 more example
Example 3
Input
codeforces
Output
codeforces
Explanation
There is no adjacent duplicated character, so the string stays unchanged.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.