Design a Food Rating System
specialist · 840 · lc medium +31 · 52.9% accepted · 1,958 likes · top 43%
Description
Build a system for rating food items by cuisine, supporting two operations:
- Update the rating of a named food item.
- Query the top-rated food item within a given cuisine type.
Implement the FoodRatings class:
- FoodRatings(String[] foods, String[] cuisines, int[] ratings) sets up the system with n food items. foods[i] is the item name, cuisines[i] is its cuisine type, and ratings[i] is its initial rating.
- void changeRating(String food, int newRating) updates the rating of the food item named food.
- String highestRated(String cuisine) returns the name of the food with the highest rating in cuisine. Break ties by returning the lexicographically smaller name.
A string x is lexicographically smaller than y if it precedes y in dictionary order.
Example 1:
Example 2:
Code