Design a Food Rating System
Problem statement
Design a food rating system. You are given three arrays of length n: foods, cuisines, and ratings. Food foods[i] belongs to cuisine cuisines[i] and starts with rating ratings[i].
Process the list operations in order. Each row is one of:
["changeRating", food, newRating]: set the rating offoodtonewRating. The rating is written as a decimal string.["highestRated", cuisine]: report the food with the highest current rating incuisine. If several foods share that rating, report the one whose name is lexicographically smallest.
Return an array with the answer to every "highestRated" operation, in order. "changeRating" operations add nothing to the result.
Function
runFoodRatings(foods: String[], cuisines: String[], ratings: int[], operations: String[][]) → String[]Examples
Example 1
foods = ["bibimbap","tteok","japchae","udon","soba","tempura"]cuisines = ["korean","korean","korean","japanese","japanese","japanese"]ratings = [6,9,9,4,7,5]operations = [["highestRated","korean"],["highestRated","japanese"],["changeRating","japchae","3"],["highestRated","korean"],["changeRating","udon","7"],["highestRated","japanese"],["changeRating","soba","2"],["highestRated","japanese"]]return = ["japchae","soba","tteok","soba","udon"]- Korean foods are
bibimbap(6),tteok(9), andjapchae(9). The two 9s tie, and"japchae"is smaller than"tteok", so the first answer is"japchae". - Japanese foods are
udon(4),soba(7), andtempura(5), so the second answer is"soba". - After
japchaedrops to 3,tteok(9) is the highest Korean food. - After
udonrises to 7, it ties withsoba."soba"is smaller, so the answer stays"soba". - After
sobadrops to 2,udon(7) is the highest, so the last answer is"udon".
Example 2
foods = ["tacos","burrito","nachos"]cuisines = ["mexican","mexican","mexican"]ratings = [5,5,3]operations = [["highestRated","mexican"],["changeRating","burrito","2"],["highestRated","mexican"],["changeRating","nachos","5"],["highestRated","mexican"]]return = ["burrito","tacos","nachos"]tacosandburritoboth have rating 5, and"burrito"is smaller, so the first answer is"burrito".- After
burritodrops to 2,tacos(5) is the highest. - After
nachosrises to 5, it ties withtacosand"nachos"is smaller.
Example 3
foods = ["pho"]cuisines = ["vietnamese"]ratings = [1]operations = [["changeRating","pho","100000000"],["highestRated","vietnamese"]]return = ["pho"]A cuisine with one food always reports that food, whatever its rating.
Constraints
1 <= n <= 500foods.length == cuisines.length == ratings.length == n1 <= foods[i].length, cuisines[i].length <= 10foods[i]andcuisines[i]contain only lowercase English letters.- All names in
foodsare distinct. 1 <= ratings[i] <= 10^8, and everynewRatingis also between1and10^8.1 <= operations.length <= 500- A
"changeRating"row has3entries and names a food infoods. A"highestRated"row has2entries and names a cuisine of at least one food.