Two collectors each own a deck of trading cards, represented as a string of lowercase letters where each letter identifies one card type (so 'a' through 'z' cover 26 possible card types). They want their two decks to eventually have the exact same composition — the same number of copies of every card type — but the only operation allowed is buying one new card of a chosen type and adding it to either collector's deck; cards already owned can never be discarded or swapped away. Each purchase counts as one operation, and the order of cards within a deck never matters, only how many of each type it holds.
Given the two starting decks s and t, determine the minimum number of purchases needed until both decks have identical composition.
Two lines. The first line contains the string s (deck 1). The second line contains the string t (deck 2). Both strings consist only of lowercase English letters.
A single integer: the minimum number of purchases required.
Example 1
Input
abc bcd
Expected
2
Explanation
Deck s has one each of a, b, c. Deck t has one each of b, c, d. Deck t is missing an 'a' (buy one 'a' for deck t) and deck s is missing a 'd' (buy one 'd' for deck s). That's 2 purchases, after which both decks hold {a,b,c,d} once each.
Example 2
Input
aabbcc abc
Expected
3
Explanation
Deck s has two each of a, b, c (6 cards). Deck t has one each of a, b, c (3 cards). Deck t needs one more of each letter to match deck s's counts, so buy one 'a', one 'b', and one 'c' for deck t: 3 purchases total.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →