I maintain three structures: (1) a map foodInfo
from food → (cuisine, currentRating), (2) for each cuisine, a max-heap keyed by (-rating, name)
so highest rating (and lexicographically smallest name on ties) is on top, and (3) a map heapByCuisine
from cuisine → its heap. When a rating changes, I update foodInfo
and push a new (-newRating, name)
into that cuisine’s heap—no deletions. In highestRated
, I lazy-clean the heap top: while the heap’s top pair doesn’t match the current rating in foodInfo
, I pop it; the first matching top is the correct answer. All operations are
class FoodRatings: