question 346 Algorithms & Complexity · medium
Customers who came back
Marketing wants the customers who ordered in January and again in February. Each month's export lists one customer ID per order, so IDs repeat. Write returning_customers(january, february). Exports have tens of thousands of rows; the hidden test counts == comparisons, so don't search a list for every ID.
Function
returning_customers(january, february)january, februarylists of customer ID strings, one per order (repeats allowed)
Returnsa sorted list of the IDs that appear in both lists, each once
Constraintat most 2,500 comparisons for two exports of 1,000 IDs
Examples
callreturning_customers(['C00077', 'C01338', 'C00077', 'C00038'], ['C00038', 'C00305', 'C00077'])returns['C00038', 'C00077']
callreturning_customers(['C00001'], ['C00002'])returns[]
callreturning_customers(['C00305', 'C00305'], ['C00305'])returns['C00305']