All problems

Raffle Drum

Medium · design

A raffle drum holds numbered tickets. Inside, the tickets sit in a row of slots numbered 0, 1, 2, ..., and no ticket number appears twice. The drum starts empty. You are given a list of operations. operations[i] is "add", "remove" or "draw", and args[i] is its single argument.

Operations are processed in the order given. Return a list with the result of every operation, in order.

Examples

Example 1

Input: operations = ["add", "add", "add", "draw", "remove", "draw"], args = [5, 8, 2, 4, 5, 4]

Output: [1, 1, 1, 8, 1, 2]

The row is 5, 8, 2. Draw 4 picks slot 4 mod 3 = 1, which holds 8. Removing 5 moves the last ticket, 2, into slot 0, so the row is 2, 8, and draw 4 now picks slot 0.

Example 2

Input: operations = ["add", "add", "remove", "remove", "draw"], args = [7, 7, 3, 7, 0]

Output: [1, 0, 0, 1, -1]

The second add finds 7 already inside, and removing 3 finds nothing. After 7 is removed, the drum is empty.

Example 3

Input: operations = ["draw", "add", "add", "remove", "draw", "draw"], args = [9, 4, 6, 4, 1, 2]

Output: [-1, 1, 1, 1, 6, 6]

Removing 4 moves 6 into slot 0, and it is then the only ticket, so every draw returns it.

Constraints