Recommendation Engine
Recommend items by matching tags, scoring and ranking โ without recommending what the user already liked.
๐งฉ Problem statement
Each item has tags. A user has liked some items. Score every other item by how many tags it shares with the userโs liked items (count shared tags per liked item). Show the top 3 as “ITEM (SCORE)”, highest first; ties keep the catalogue order.
๐ Requirements
- Matching
- Scoring
- Ranking
- Similarity
๐ฅ Inputs
- ITEMS: map item โ list of tags
- LIKED: list of items
๐ค Outputs
- Top 3 recommendations with scores
๐ Rules
- Never recommend an already-liked item
- Ties: catalogue order
๐ง Constraints
- Each item has 1โ5 tags
๐งญ Suggested approach
- Collect the tags of liked items
- Score each other item by shared tags
- Pick the top 3 by repeated max
๐ง Required concepts
- Maps
- Lists
- Counting
- Ranking
Design your solution here. Use Run to dry-run it step by step and Run tests to check it. Hints unlock one at a time โ try on your own first!
๐งช Edge cases to test
- A user who liked nothing
- Fewer than 3 items left to recommend
- Many ties
๐ Complexity analysis
Weights O(liked ร tags); scoring O(items ร tags); ranking O(3 ร items).
๐ Solution walkthrough (open after youโve tried!)
First the liked itemsโ tags are counted into a weight map โ tags the user likes more get bigger weights. Each other item scores the sum of the weights of its tags. Ranking picks the highest score three times (strictly greater keeps catalogue order on ties) and removes each pick so it isnโt chosen again.
๐ Challenge extensions
- Use similarity between users (people who liked X also liked Y)
- Penalise items with tags the user disliked
- Explain why each item was recommended