question 342 Algorithms & Complexity · easy
Fix the unknown-SKU report
Before an import, a script lists the SKUs in incoming orders that aren't in the product catalogue (a dictionary from SKU to product name). It reports every SKU as unknown, even ones the catalogue clearly has, and it is slow on a big catalogue. Find the bug and fix it without changing what the report should contain.
Function
unknown_skus(order_skus, catalogue)cataloguea dictionary: SKU → product name (a name may be an empty string while it is being written)
Returnseach SKU from
order_skus that is not a key of the catalogue, once, in the order first seenExamples
callunknown_skus(['HOM-22847', 'GRO-10442', 'SPO-11681', 'GRO-10442'], {'SPO-11681': 'Ultra Bike Light', 'HOM-22847': 'Deluxe Vase', 'ELE-24781': 'Organic Speaker'})returns['GRO-10442']
callunknown_skus(['BOO-58412', 'HOM-52782'], {'SPO-11681': 'Ultra Bike Light', 'HOM-22847': 'Deluxe Vase', 'ELE-24781': 'Organic Speaker'})returns['BOO-58412', 'HOM-52782']
callunknown_skus(['ELE-24781'], {'SPO-11681': 'Ultra Bike Light', 'HOM-22847': 'Deluxe Vase', 'ELE-24781': 'Organic Speaker'})returns[]