Design a Food Rating System
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Design a system that tracks ratings for foods and can report the best food of a given cuisine.
- FoodRatings(foods, cuisines, ratings) initializes the system: food foods[i] belongs to cuisine cuisines[i] and starts with rating ratings[i]. Food names are distinct.
- changeRating(food, newRating) sets that food's rating to newRating.
- highestRated(cuisine) returns the name of the food with the **highest rating** in that cuisine. If several foods tie, return the **lexicographically smallest** name.
changeRating is only called with existing foods, and highestRated only with cuisines that have at least one food.
Examples
Constraints
- `1 <= foods.length <= 2 * 10^4`, and `foods.length == cuisines.length == ratings.length`.
- Names and cuisines have 1 to 10 lowercase English letters; all food names are distinct.
- `1 <= ratings[i], newRating <= 10^8`
- At most 2 * 10^4 calls in total.
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.