Rank Local Businesses by Time-Decayed Neighbor Recommendations
Last updated: November 29, 2026
Quick Overview
Design a data structure that records neighbor recommendations (Faves) for local businesses with timestamps and weights, and returns the top k businesses in a neighborhood by an exponentially decayed score at query time.
Nextdoor
November 29, 20260
0
0 solved
Design a data structure that records neighbor recommendations (Faves) for local businesses with timestamps and weights, and returns the top k businesses in a neighborhood by an exponentially decayed score at query time.
Nextdoor surfaces trusted local businesses through neighbor recommendations, and a recommendation from three years ago should count less than one from last month. The interviewer looks for the trick that makes decay cheap (storing scores against a fixed base time) and for sensible handling of overflow and ties.
What the Interviewer Expects
- Define the decayed score formula with a half-life
- Notice that decay multiplies every score by the same factor, so ranking at a fixed time needs no per-item updates
- Store contributions relative to a base time and rebase to avoid overflow
- Use a size-k heap for top k selection
- Break ties deterministically
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you shard this when there are millions of businesses across thousands of neighborhoods?
- How do you stop one household from inflating a business with many recommendations?
- Would you rank by raw decayed sum or by a Bayesian average that also uses negative signals? Why?
- How would you include recommendations from nearby neighborhoods with a lower weight?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Operations: add(neighborhood, business, t, weight) and top_k(neighborhood, now, k). Score is with half-life days. Adds are frequent; queries are...
High-Level Design
Key insight: . The second factor is shared by every business, so store raw += w * 2^((t - T0)/H) and multiply by one scale factor at que...