Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class FoodRatings:
- def __init__(self, foods: List[str], cuisines: List[str], ratings: List[int]):
- self.foodRating = {}
- self.cuisineRatingFood = defaultdict(list)
- self.cuisineFood = {}
- for food, cuisine, rating in zip(foods, cuisines, ratings):
- self.foodRating[food] = rating
- heapq.heappush(self.cuisineRatingFood[cuisine], [-rating, food])
- self.cuisineFood[food] = cuisine
- def changeRating(self, food: str, newRating: int) -> None:
- self.foodRating[food] = newRating
- cuisine = self.cuisineFood[food]
- heapq.heappush(self.cuisineRatingFood[cuisine], [-newRating, food])
- def highestRated(self, cuisine: str) -> str:
- heap = self.cuisineRatingFood[cuisine]
- while heap:
- top, food = heapq.heappop(heap)
- if -top == self.foodRating[food]:
- return food
- return ""
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement