FunctionRacerProblemsRace

Second Sale

HardpandasPython

users has columns id and favorite (a brand). sales has seller, day and brand, with at most one sale per seller per day.

Return a dict from every user id to True when the brand of that user's second sale, counting by day, is their favorite brand. Otherwise, and for users with fewer than two sales, the value is False.

Example 1

users {"id":[1,2,3],"favorite":["Kora","Vine","Kora"]}
sales {"seller":[1,1,2,2,2,3],"day":[9,2,5,7,1,4],"brand":["Kora","Vine","Vine","Kora","Kora","Kora"]}
returns {"1":true,"2":true,"3":false}

User 1 sold Vine on day 2 and then Kora on day 9: the second sale is their favorite. User 2's second sale (day 5) is Vine, their favorite. User 3 sold only once.

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