Design a Food Rating System - Leetcode 2353 - Python

preview_player
Показать описание


0:00 - Read the problem
0:28 - Drawing Explanation
5:49 - Coding Explanation

leetcode 2353

#neetcode #leetcode #python
Рекомендации по теме
Комментарии
Автор

This is the only channel on youtube which i follow religiously, If someday I make it to tech, It will be all because of this channel.

schrodingerskatt
Автор

Learned something today with the negative on the rating to get the sorting right for the second element in the tuple. Great solution!

AnimalKingDaniel
Автор

This was a really good problem, especially since Sorted Sets aren't covered in the original Neetcode 150!

theteacher
Автор

I had a hashmap of max heaps instead of sortedsets and that gave me TLE after 73 test cases. It would be interesting to dive into how sorted sets in Python work after I solve this one because the interviewer could ask me the underlying data structure of the sorted set. Thanks for the video!

gmh
Автор

I am writing this comment before watching the video, I came up with my own solution under 15 minutes involving hashmaps and max heap in python, that solution was able to pass 71/77 testcases. Now, I am watching this video after banging my head for straight 30 minutes. Hope I will find a coding mechanism which I didn't knew earlier.

asparshraj
Автор

In my opinion it's a pretty good problem. I did solve it on my own but I had to see the hints.

yashaggarwal
Автор

Making the ratings of each tuple negative to "trick" the SortedSet to sort them in descending order is such a smart move, didn't have to write any custom class and comparator like I did and waste time, will definitely keep that it mind next time.

sy_alty
Автор

Hmm yeah I'll think i will just go with a naive approach 😅

Vancha
Автор

This question felt like playing with Russian dolls as a 4 year old. I literally could not believe this was the actual solution. I better get used to dumb things like this.

ChrisBakare
Автор

You skipped the part of the problem about " If there is a tie, return the item with the lexicographically smaller name."

SatansSpatula
Автор

Cant we do hashMap[cuisine] --> mapped to priority queue [(rating, food)]?

BirajDahal-zu
Автор

coding this problem in cpp is very frustrating, .... ... I solved this in cpp within 40 mins but the time limit got 2080 ms... but still i solved this...

tanishq
Автор

I don't think I'll be able to solve this in a 40 minute interview

yang
Автор

You can also maintain a single hash map to store a tuple of the form - (cuisines[i], ratings[i]) and change the ratings.

self.food_map = {}

# initialize:
self.food_map[foods[i]] = (cuisines[i], ratings[i])

# changeRating:
...
self.food_map[food] = (cuisine, newRating)

masterbyte
Автор

Came here with the hope someone would say a word about why TreeMap works, but Heap gives TLE even though they have the same O times for main operations.

andreikiryieuski
Автор

I really feel like this is a hard problem...

bundiderp
welcome to shbcf.ru