All problems

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).

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