Before any personalisation, every recommender needs a popularity baseline: rank items by how many people interacted with them and show everybody the same list. It's also the fallback for a brand-new user you know nothing about.
Task: write popularity_rank(interactions) returning the item ids ordered most popular first.
interactions is a list of [user, item] pairs, one per interaction.The tie-break matters more here than anywhere, because popularity counts tie constantly in the long tail — thousands of items with exactly one interaction each. Without a rule, their order is whatever the dictionary happens to produce.
Worth knowing what this baseline does and doesn't do. It's genuinely hard to beat on raw accuracy metrics, because popular things are popular for a reason, and it cold-starts perfectly. But it recommends the same thing to everyone, so it has zero personalisation and it actively reinforces itself: showing popular items makes them more popular, which pushes them further up the list. That feedback loop is why catalogue coverage and novelty get measured alongside accuracy — accuracy alone would tell you this baseline is excellent.