We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
class FoodRatings { HashMap<String, PriorityQueue<Food>> x = new HashMap<>(); // get pq from cuisine name HashMap<String, Food> menu = new HashMap<>(); // get Food (object) by food name public FoodRatings(String[] foods, String[] cuisines, int[] ratings) { for(int i=0; i<foods.length; i++){ if(!x.containsKey(cuisines[i])){ PriorityQueue<Food> pq = new PriorityQueue<>((a,b)-> b.rating-a.rating==0 ? a.name.compareTo(b.name) : b.rating-a.rating); x.put(cuisines[i], pq); } Food curr = new Food(foods[i], cuisines[i], ratings[i]); PriorityQueue<Food> pq = x.get(cuisines[i]); pq.add(curr); menu.put(foods[i], curr); } } public void changeRating(String food, int newRating) { Food curr = menu.get(food); PriorityQueue<Food> pq = x.get(curr.cuisine); pq.remove(curr); curr.rating = newRating; pq.add(curr); } public String highestRated(String cuisine) { return x.get(cuisine).peek().name; } } class Food{ int rating; String name, cuisine; Food(String name, String cuisine, int rating){ this.name = name; this.rating = rating; this.cuisine = cuisine; } } /** * Your FoodRatings object will be instantiated and called as such: * FoodRatings obj = new FoodRatings(foods, cuisines, ratings); * obj.changeRating(food,newRating); * String param_2 = obj.highestRated(cuisine); */
The text was updated successfully, but these errors were encountered:
No branches or pull requests
The text was updated successfully, but these errors were encountered: