Practice/Atlassian/Leetcode 2353. Design a Food Rating System
CodingMust
Design a data structure that manages a restaurant menu rating system. The system needs to track multiple food items, each associated with a specific cuisine type and a numerical rating. Your implementation must support two primary operations:
When multiple foods in the same cuisine have identical ratings, return the one that comes first alphabetically (lexicographically smallest name).
Your FoodRatings class should be initialized with three arrays of equal length:
foods: names of food items (all unique)cuisines: the cuisine type for each corresponding foodratings: the initial rating for each corresponding foodchangeRating(food, newRating) that updates a specific food's ratinghighestRated(cuisine) that returns the name of the food with the highest rating for the specified cuisinefoods.length ≤ 2 × 104foods.length = cuisines.length = ratings.lengthfoods[i].length, cuisines[i].length ≤ 10ratings[i] ≤ 108foods[i], cuisines[i] consist of lowercase English letterschangeRating and highestRatedchangeRating will only be called on foods that exist in the systemExample 1:
Input: Initialize: foods = ["kimchi", "bulgogi", "bibimbap"], cuisines = ["korean", "korean", "korean"], ratings = [9, 8, 10] Operations: highestRated("korean") Output: "bibimbap" Explanation: Bibimbap has the highest rating (10) among Korean foods.
Example 2:
Input: Initialize: foods = ["pad-thai", "curry", "pad-thai-gai"], cuisines = ["thai", "thai", "thai"], ratings = [7, 7, 6] Operations: highestRated("thai") Output: "curry" Explanation: Both pad-thai and curry have rating 7, but "curry" comes first alphabetically.
Example 3:
Input: Initialize: foods = ["lasagna", "tiramisu"], cuisines = ["italian", "italian"], ratings = [8, 9] Operations: 1. changeRating("lasagna", 11) 2. highestRated("italian") Output: "lasagna" Explanation: After the update, lasagna has rating 11, making it the highest-rated Italian food.