Skip to main content
Back to problems
Leetcode
Easy
Arrays
Strings
Hash Maps
Bit Manipulation
Find The Difference

Find the one extra character that appears in a shuffled version of a string.

Acceptance 0%
Problem Statement

Given two strings ss and tt, where tt is formed by shuffling the characters of ss and adding exactly one extra character at an arbitrary position, identify the extra character.

Return that character as a single-letter string.

Input Format

  • Two strings ss and tt
  • tt contains all characters of ss plus one additional character
  • Character order in both strings may be arbitrary

Output Format

  • Return the extra character that appears in tt but not in ss

Constraints

  • 0s1040 \le |s| \le 10^4
  • t=s+1|t| = |s| + 1
  • Strings contain lowercase English letters in the common LeetCode formulation
Examples
Sample cases returned by the problem API.

Example 1

Input

s = "abcd", t = "abcde"

Output

"e"

Explanation

The string t contains every character from s plus one extra character, e.

Example 2

Input

s = "ae", t = "aea"

Output

"a"

Explanation

The extra character in t is a.

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.