Skip to main content
Back to problems
Codeforces
Medium
Strings
Arrays
Hash Maps
Fixing Typos

Find and remove a typo that creates a repeated character in a word.

Acceptance 0%
Problem Statement

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 ii 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 ss 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

  • 1s1051 \le |s| \le 10^5
  • ss contains only lowercase English letters.
Examples
Sample cases returned by the problem API.

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.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.