Sticker Copies Board
Hard · design
A collector swaps stickers with friends. Each sticker has a design name, and the collector can hold any number of copies of the same design. At the start the collector holds nothing. You are given two lists of the same length: operations[i] is one of "gain", "give", "most" or "fewest", and designs[i] is a design name (for "most" and "fewest" it is the empty string "" and should be ignored).
"gain"adds one more copy of the design."give"removes one copy of the design. If the collector holds no copy of it, nothing happens. A design with no copies left is no longer held."most"asks for the biggest number of copies the collector holds of one design, and how many designs have exactly that many copies. Answer with the pair[copies, designs]."fewest"asks the same for the smallest number of copies among the designs that are currently held.
If nothing is held, the answer to "most" and "fewest" is [0, 0].
Return a list with the answer to every "most" and "fewest", in the order they appear.
Examples
Example 1
Input: operations = ["gain", "gain", "gain", "most", "fewest", "give", "fewest", "most"], designs = ["owl", "fox", "owl", "", "", "fox", "", ""]
Output: [[2, 1], [1, 1], [2, 1], [2, 1]]
After the gains the collector holds 2 copies of owl and 1 of fox. Giving away the last fox leaves only owl, so the smallest count is now 2.
Example 2
Input: operations = ["fewest", "give", "gain", "gain", "gain", "gain", "gain", "most", "fewest"], designs = ["", "owl", "owl", "fox", "fox", "bee", "bee", "", ""]
Output: [[0, 0], [2, 2], [1, 1]]
The album is empty at first, so the answer is [0, 0] and giving away an owl does nothing. Then owl, fox and bee each end up with 1, 2 and 2 copies.
Constraints
- 1 <= len(operations) <= 5 * 10^4
- len(designs) == len(operations)
- operations[i] is gain, give, most or fewest
- A design name is made of 1 to 10 lower-case letters and digits