Skip to content

Practice Design a Food Rating System

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2353
LeetCode Problem

Design a Food Rating System

Problem Statement

FoodRatings(foods,cuisines,ratings) associates each distinct food name with its cuisine and rating. changeRating(food,newRating) replaces its rating. highestRated(cuisine) returns the highest-rated food of that cuisine, breaking ties by lexicographically smallest name. Practice approach: Keep current food records and a per-cuisine ordered set or heap sorted by descending rating then ascending name. Heap implementations must discard stale entries after rating changes. Cuisine membership does not change. Test equal ratings and lowering the current winner.

Source: Design a Food Rating System on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
["FoodRatings","highestRated","changeRating","highestRated","changeRating","highestRated"]
[[["apple","bread"],["local","local"],[5,5]],["local"],["bread",7],["local"],["bread",4],["local"]]
Output
[null,"apple",null,"bread",null,"apple"]
Explanation

Tied ratings choose apple alphabetically; rating updates change the winner.

Constraints

1 <= n <= 2 * 10^4
foods, cuisines, and ratings have length n.
Names contain 1 to 10 lowercase letters; food names are distinct.
1 <= rating <= 10^8
Queried foods and cuisines exist.
At most 2 * 10^4 total calls.

Related LeetCode Problems

Practice more problems similar to Design a Food Rating System.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.