The Filter Restaurants interview question asks you to filter a list of restaurants based on three user preferences: whether they are vegan-friendly, their maximum price, and their maximum distance. After filtering, you must return the IDs of the qualifying restaurants, sorted by their rating in descending order. If two restaurants have the same rating, the one with the higher ID comes first.
Companies like Yelp ask the Filter Restaurants coding problem to test your ability to handle multi-level sorting and filtering. It evaluates how you organize your logic to process multiple constraints and whether you can use custom comparators efficiently. It's a practical problem that mirrors real-world search and recommendation systems.
This problem follows a Filter and Sort pattern.
veganFriendly is 1, the restaurant must also have veganFriendly as 1. If 0, any restaurant is fine.price <= maxPrice.distance <= maxDistance.rating (descending).id (descending).Restaurants: [[1, 4, 1, 10, 5], [2, 8, 0, 50, 10], [3, 8, 1, 30, 4]] (ID, Rating, Vegan, Price, Distance)
Preferences: veganFriendly=1, maxPrice=40, maxDistance=10.
[3, 1].veganFriendly=0 means the user only wants non-vegan restaurants. Usually, 0 means the user doesn't care.Practice using custom comparators in your language of choice (e.g., lambda in Python, Comparator in Java). Multilevel sorting is a very common requirement in production code.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Merge Intervals | Medium | Solve | |
| Check if Grid can be Cut into Sections | Medium | Solve | |
| Count Days Without Meetings | Medium | Solve | |
| Count Ways to Group Overlapping Ranges | Medium | Solve | |
| Find Maximal Uncovered Ranges | Medium | Solve |