Leetcode Problem 2353. Design a Food Rating System

2353. Design a Food Rating System

Leetcode Solutions

Hash Maps and Priority Queue

  1. Define a Food class with properties foodRating and foodName.
  2. Overload the comparison operator to sort by rating first, then lexicographically by name.
  3. Initialize three hash maps: foodRatingMap, foodCuisineMap, and cuisineFoodMap.
  4. During initialization, populate the hash maps and priority queues with the given data.
  5. For changeRating, update foodRatingMap and add a new Food object to the priority queue in cuisineFoodMap.
  6. For highestRated, retrieve and remove elements from the priority queue until the top element's rating matches the current rating in foodRatingMap.
  7. Return the name of the food with the highest rating for the requested cuisine.
UML Thumbnail

Hash Maps and Sorted Set

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...