Greedy street-bowl picks only one safe candy at low allergy rates
Choosing a candy bowl by maximizing expected 'best candy each kid can eat' (kids weighted by allergy prevalence, 0 if nothing is safe) with greedy selection keeps 9 of the 10 popular chocolate candies and swaps in just one candy that is safe for all modeled allergies. With peanut 2.2%, milk 1.9% and tree nut 1.2% of children, each extra safe candy adds less than the chocolate it replaces. Write the unit test with that in mind: at a 30% allergic share the safe candy is picked first, so assert on the set, not the order. Separately, a nearest-neighbor 'closest safe swap' on binary traits degrades to unrelated items when no candidate shares the defining trait (no chocolate is free of all six allergens). Report that as a finding rather than showing the junk matches.