commit 5875d818b502313739a0070c90d54a31d4a6f4af
parent d82261e1b5da10eab3d231d7353f142e5b786518
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Sun, 17 Dec 2023 20:28:57 +0000
Daily Problem
Diffstat:
2 files changed, 24 insertions(+), 0 deletions(-)
diff --git a/Problems/2353.cpp b/Problems/2353.cpp
@@ -0,0 +1,23 @@
+class FoodRatings {
+ unordered_map<string, set<pair<int, string>>> order;
+ unordered_map<string, string> category;
+ unordered_map<string, int> rating;
+
+ public:
+ FoodRatings(const vector<string> &foods, const vector<string> &cuisines, const vector<int> &ratings) {
+ for (int i = 0; i < foods.size(); i++) {
+ order[cuisines[i]].emplace(-ratings[i], foods[i]);
+ category.emplace(foods[i], cuisines[i]);
+ rating.emplace(foods[i], ratings[i]);
+ }
+ }
+
+ void changeRating(const string &food, int newRating) {
+ auto &st = order[category[food]];
+ st.erase(st.find({-rating[food], food}));
+ rating[food] = newRating;
+ st.emplace(-rating[food], food);
+ }
+
+ string highestRated(const string &cuisine) { return order[cuisine].begin()->second; }
+};
diff --git a/README.md b/README.md
@@ -935,6 +935,7 @@ for solving problems.
| 2343 | Medium | [Query Kth Smallest Trimmed Number](Problems/2343.cpp) |
| 2348 | Medium | [Number of Zero-Filled Subarrays](Problems/2348.cpp) |
| 2352 | Medium | [Equal Row and Column Pairs](Problems/2352.cpp) |
+| 2353 | Medium | [Design a Food Rating System](Problems/2353.cpp) |
| 2356 | Easy | [Number of Unique Subjects Taught by Each Teacher](Problems/2356.cpp) |
| 2358 | Medium | [Maximum Number of Groups Entering a Competition](Problems/2358.cpp) |
| 2359 | Medium | [Find Closest Node to Given Two Nodes](Problems/2359.cpp) |