All problems

Gate Scanner Rejects

Easy · hash set

A concert has a list of valid ticket codes, valid. No code appears twice in it.

At the gate, every ticket that arrives is scanned, and the scanned codes are recorded in order in scans. The same code can be scanned more than once (someone may try again, or pass a ticket back).

Return the codes from scans that are not in valid, in the order they were scanned. Keep repeats: if a bad code was scanned three times, it appears three times in the answer. If every scan is fine, return an empty list.

Examples

Example 1

Input: valid = [101, 205, 330], scans = [205, 999, 101, 999, 330, 42]

Output: [999, 999, 42]

999 and 42 are not valid codes, and 999 was scanned twice.

Example 2

Input: valid = [7, 8], scans = [8, 7, 8]

Output: []

Constraints