Find the Difference
Real-world version: The Sort That Joined the TrayThe statement here is our own: the same inputs, outputs and technique.
A hand-press shop stores its metal letter sorts loose in a tray. Before a print run the apprentice empties the tray and writes down each sort as a lowercase letter, in whatever order the sorts came to hand; that record is before. After the run one extra sort has been dropped into the tray, and the apprentice empties it and writes it down again, once more in whatever order the sorts came to hand; that record is after.
So after holds every sort that before holds, in some order, plus exactly one more. Neither record tells you anything about where in the tray a sort was sitting, and the extra sort may well be a letter the tray already held several of.
Return the letter of the sort that was added, as a single-character string.
Examples
Example 1
- Input
- before = "lull", after = "llulu"
- Output
- "u"
Both writings hold three `l` sorts, but the later one holds two `u` sorts where the earlier one held a single `u`.
Example 2
- Input
- before = "", after = "q"
- Output
- "q"
The tray was empty before the job, so the one sort written down afterwards is the sort that was dropped in.
Example 3
- Input
- before = "dq", after = "adq"
- Output
- "a"
The `d` and the `q` appear once in each writing, and the later writing carries an `a` that the earlier one has nothing to match.
Example 4
- Input
- before = "spandrel", after = "landpress"
- Output
- "s"
Every letter appears the same number of times in both writings apart from `s`, which turns up twice after the job and once before it.
Constraints
- 0 <= before.length <= 1000
- after.length == before.length + 1
- before and after consist of lowercase English letters.
- after is a rearrangement of before with one extra letter inserted.
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def added_sort(before: str, after: str) -> str:public char addedSort(String before, String after)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 10 test cases: 10 passed
- Passed: 4 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's