Deliveroo interview question

a long exercise about array intersection