A neighborhood loyalty club keeps a roster of its members alongside a running log of purchase receipts, each receipt stamped with the id of the member who made it. Members are listed once, in the order they joined the club; a member can appear on any number of receipts, or none at all. Produce the names of every member who has never redeemed a single receipt.
Line 1: an integer M, the number of loyalty members.
Next M lines: an integer memberId followed by a name, memberId name — memberId is unique across the M lines, and name consists of 1 to 20 lowercase English letters (names need not be unique).
Next line: an integer P, the number of purchase receipts.
Next P lines: a single integer memberId, the member who made that receipt — the same member may appear on multiple receipts, and every memberId here is guaranteed to belong to a member listed in the roster.
Print the name of every member with zero purchase receipts, one per line, in the same order those members appear in the roster. If every member made at least one purchase, print nothing.
^[a-z]{1,20}$Example 1
Input
3 1 alice 2 bob 3 carol 1 2
Expected
alice carol
Explanation
The roster lists alice (id 1), bob (id 2), and carol (id 3) in that order. The one purchase receipt belongs to member id 2 (bob), so bob is excluded. Alice and carol have zero receipts, so they are printed in roster order: alice then carol.
Example 2
Input
2 1 dave 2 erin 3 1 1 2
Expected
(empty)Explanation
Dave (id 1) has two receipts and erin (id 2) has one receipt, so both members have at least one purchase. No member qualifies, so the output is empty.
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 →