Top K Businesses by Bayesian Smoothed Star Rating

Last updated: November 29, 2026

Quick Overview

Given a stream of (business_id, stars) review events, return the k business ids with the highest smoothed rating, where each business's average is pulled toward a global prior so a single five star review does not beat hundreds of strong reviews.

Yelp
Coding & Algorithms
Software Engineer
Yelp
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Easy

0

0

0 solved


Given a stream of (business_id, stars) review events, return the k business ids with the highest smoothed rating, where each business's average is pulled toward a global prior so a single five star review does not beat hundreds of strong reviews.

Ranking by raw average is a known trap on any review platform, and Yelp interviewers like to see whether you notice it. The coding part is a frequency map plus a size k heap, but the conversation about why smoothing matters is what separates candidates.

What the Interviewer Expects
  • Explain why raw averages over rank businesses with few reviews
  • Define the smoothed score with a prior mean and prior weight
  • Aggregate sums and counts in one pass with hash maps
  • Select top k with a heap in O(n log k) rather than a full sort
  • Specify a deterministic tie break
Key Topics to Cover
hash maps
heaps
top-k
Bayesian average
ranking
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you pick the prior mean and weight, per category or globally?
  • How would you keep this top k current as reviews arrive in real time?
  • How do you handle review edits and removals flagged by the recommendation software?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: a list of (business_id, stars) with stars in 1..5, and an integer k. Output: up to k ids ordered by smoothed score, ties broken by id ascending. The score is Cm+∑siC+n\frac{C m + \sum s_i}{C + n} wh...

High-Level Design

First pass: accumulate total stars and count per business in two dictionaries. Then compute each business's score and keep the best k. A business with one 5 star review scores (10*3.5+5)/11 = 3.64, wh...


Submit Your Answer
Markdown supported

Related Questions