Identify the Added Letter

Quick Overview

Practice identifying one added lowercase letter after a string is shuffled. Handle repeated letters, an empty original string, and a character output.

Identify the Added Letter

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

# Identify the Added Letter String `t` was made by shuffling the letters of string `s` and adding one additional lowercase letter at some position. Return that added letter. ### Function `char findTheDifference(string s, string t)` ### Example 1 ```text Input: s = "aba", t = "baaa" Output: "a" ``` `t` contains one more `a` than `s` does. ### Example 2 ```text Input: s = "", t = "q" Output: "q" ``` ### Constraints - `0 <= s.length <= 1000`. - `t.length == s.length+1`. - Both strings contain only lowercase English letters. - `t` satisfies the stated shuffle-and-add construction. ### Clarifications The added letter may already occur in `s`. Shuffling can change every position, so the first positional mismatch need not identify the added letter. Return a single character, not its index. ### What a Strong Answer Covers - Rearrangement and repeated letters. - An empty original string. - Why the answer is the uniquely added occurrence's letter. - Correctness and resource bounds.

Overview: Practice identifying one added lowercase letter after a string is shuffled. Handle repeated letters, an empty original string, and a character output.

Amazon logo
Amazon
easySoftware EngineerOtherCoding & Algorithms
0
0

Identify the Added Letter

String t was made by shuffling the letters of string s and adding one additional lowercase letter at some position. Return that added letter.

Function

char findTheDifference(string s, string t)

Example 1

Input: s = "aba", t = "baaa"
Output: "a"

t contains one more a than s does.

Example 2

Input: s = "", t = "q"
Output: "q"

Constraints

  • 0 <= s.length <= 1000 .
  • t.length == s.length+1 .
  • Both strings contain only lowercase English letters.
  • t satisfies the stated shuffle-and-add construction.

Clarifications

The added letter may already occur in s. Shuffling can change every position, so the first positional mismatch need not identify the added letter. Return a single character, not its index.

What a Strong Answer Covers Guidance

  • Rearrangement and repeated letters.
  • An empty original string.
  • Why the answer is the uniquely added occurrence's letter.
  • Correctness and resource bounds.