Trains the technique from
LeetCode 389Find the DifferenceThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
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.
Example 1
Both writings hold three `l` sorts, but the later one holds two `u` sorts where the earlier one held a single `u`.
Example 2
The tray was empty before the job, so the one sort written down afterwards is the sort that was dropped in.
Example 3
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
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.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def added_sort(before: str, after: str) -> str:public char addedSort(String before, String after)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.