Skip to content

Commit cd05176

Browse files
committed
Create README - LeetHub
1 parent a99f82b commit cd05176

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<h2><a href="https://leetcode.com/problems/design-a-food-rating-system/?envType=daily-question&envId=2025-09-17">2429. Design a Food Rating System</a></h2><h3>Medium</h3><hr><p>Design a food rating system that can do the following:</p>
2+
3+
<ul>
4+
<li><strong>Modify</strong> the rating of a food item listed in the system.</li>
5+
<li>Return the highest-rated food item for a type of cuisine in the system.</li>
6+
</ul>
7+
8+
<p>Implement the <code>FoodRatings</code> class:</p>
9+
10+
<ul>
11+
<li><code>FoodRatings(String[] foods, String[] cuisines, int[] ratings)</code> Initializes the system. The food items are described by <code>foods</code>, <code>cuisines</code> and <code>ratings</code>, all of which have a length of <code>n</code>.
12+
13+
<ul>
14+
<li><code>foods[i]</code> is the name of the <code>i<sup>th</sup></code> food,</li>
15+
<li><code>cuisines[i]</code> is the type of cuisine of the <code>i<sup>th</sup></code> food, and</li>
16+
<li><code>ratings[i]</code> is the initial rating of the <code>i<sup>th</sup></code> food.</li>
17+
</ul>
18+
</li>
19+
<li><code>void changeRating(String food, int newRating)</code> Changes the rating of the food item with the name <code>food</code>.</li>
20+
<li><code>String highestRated(String cuisine)</code> Returns the name of the food item that has the highest rating for the given type of <code>cuisine</code>. If there is a tie, return the item with the <strong>lexicographically smaller</strong> name.</li>
21+
</ul>
22+
23+
<p>Note that a string <code>x</code> is lexicographically smaller than string <code>y</code> if <code>x</code> comes before <code>y</code> in dictionary order, that is, either <code>x</code> is a prefix of <code>y</code>, or if <code>i</code> is the first position such that <code>x[i] != y[i]</code>, then <code>x[i]</code> comes before <code>y[i]</code> in alphabetic order.</p>
24+
25+
<p>&nbsp;</p>
26+
<p><strong class="example">Example 1:</strong></p>
27+
28+
<pre>
29+
<strong>Input</strong>
30+
[&quot;FoodRatings&quot;, &quot;highestRated&quot;, &quot;highestRated&quot;, &quot;changeRating&quot;, &quot;highestRated&quot;, &quot;changeRating&quot;, &quot;highestRated&quot;]
31+
[[[&quot;kimchi&quot;, &quot;miso&quot;, &quot;sushi&quot;, &quot;moussaka&quot;, &quot;ramen&quot;, &quot;bulgogi&quot;], [&quot;korean&quot;, &quot;japanese&quot;, &quot;japanese&quot;, &quot;greek&quot;, &quot;japanese&quot;, &quot;korean&quot;], [9, 12, 8, 15, 14, 7]], [&quot;korean&quot;], [&quot;japanese&quot;], [&quot;sushi&quot;, 16], [&quot;japanese&quot;], [&quot;ramen&quot;, 16], [&quot;japanese&quot;]]
32+
<strong>Output</strong>
33+
[null, &quot;kimchi&quot;, &quot;ramen&quot;, null, &quot;sushi&quot;, null, &quot;ramen&quot;]
34+
35+
<strong>Explanation</strong>
36+
FoodRatings foodRatings = new FoodRatings([&quot;kimchi&quot;, &quot;miso&quot;, &quot;sushi&quot;, &quot;moussaka&quot;, &quot;ramen&quot;, &quot;bulgogi&quot;], [&quot;korean&quot;, &quot;japanese&quot;, &quot;japanese&quot;, &quot;greek&quot;, &quot;japanese&quot;, &quot;korean&quot;], [9, 12, 8, 15, 14, 7]);
37+
foodRatings.highestRated(&quot;korean&quot;); // return &quot;kimchi&quot;
38+
// &quot;kimchi&quot; is the highest rated korean food with a rating of 9.
39+
foodRatings.highestRated(&quot;japanese&quot;); // return &quot;ramen&quot;
40+
// &quot;ramen&quot; is the highest rated japanese food with a rating of 14.
41+
foodRatings.changeRating(&quot;sushi&quot;, 16); // &quot;sushi&quot; now has a rating of 16.
42+
foodRatings.highestRated(&quot;japanese&quot;); // return &quot;sushi&quot;
43+
// &quot;sushi&quot; is the highest rated japanese food with a rating of 16.
44+
foodRatings.changeRating(&quot;ramen&quot;, 16); // &quot;ramen&quot; now has a rating of 16.
45+
foodRatings.highestRated(&quot;japanese&quot;); // return &quot;ramen&quot;
46+
// Both &quot;sushi&quot; and &quot;ramen&quot; have a rating of 16.
47+
// However, &quot;ramen&quot; is lexicographically smaller than &quot;sushi&quot;.
48+
</pre>
49+
50+
<p>&nbsp;</p>
51+
<p><strong>Constraints:</strong></p>
52+
53+
<ul>
54+
<li><code>1 &lt;= n &lt;= 2 * 10<sup>4</sup></code></li>
55+
<li><code>n == foods.length == cuisines.length == ratings.length</code></li>
56+
<li><code>1 &lt;= foods[i].length, cuisines[i].length &lt;= 10</code></li>
57+
<li><code>foods[i]</code>, <code>cuisines[i]</code> consist of lowercase English letters.</li>
58+
<li><code>1 &lt;= ratings[i] &lt;= 10<sup>8</sup></code></li>
59+
<li>All the strings in <code>foods</code> are <strong>distinct</strong>.</li>
60+
<li><code>food</code> will be the name of a food item in the system across all calls to <code>changeRating</code>.</li>
61+
<li><code>cuisine</code> will be a type of cuisine of <strong>at least one</strong> food item in the system across all calls to <code>highestRated</code>.</li>
62+
<li>At most <code>2 * 10<sup>4</sup></code> calls <strong>in total</strong> will be made to <code>changeRating</code> and <code>highestRated</code>.</li>
63+
</ul>

0 commit comments

Comments
 (0)