FunctionRacerProblemsRace

Bought Together Most

HardpandasPython

items has columns order and product, with each product at most once per order. Return [a, b] with a < b alphabetically: the two products that share the most orders. If pairs tie, return the pair that comes first alphabetically (compare a, then b).

Example 1

items {"order":[1,1,1,2,2,3,3],"product":["tea","milk","jam","milk","tea","jam","milk"]}
returns ["jam","milk"]

jam and milk share orders 1 and 3. milk and tea share orders 1 and 2. Both pairs have 2, and jam, milk comes first alphabetically.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More pandas problems