Filter Restaurants by Vegan-Friendly, Price and Distance
Given the array restaurants where restaurants[i] = [idi, ratingi, veganFriendlyi, pricei, distancei], filter the restaurants using three filters.
The veganFriendly filter will be either:
1, meaning you should only include restaurants withveganFriendlyiset to1.0, meaning you can include any restaurant.
In addition, the filters maxPrice and maxDistance are the maximum values for the price and distance of restaurants you should consider, respectively.
Return the array of restaurant IDs after filtering, ordered by rating from highest to lowest. For restaurants with the same rating, order them by id from highest to lowest. For simplicity, veganFriendlyi and veganFriendly take value 1 when true and 0 when false.
Example 1
Input
restaurants = [[1,4,1,40,10],[2,8,0,50,5],[3,8,1,30,4],[4,10,0,10,3],[5,1,1,15,1]], veganFriendly = 1, maxPrice = 50, maxDistance = 10Output
[3,1,5]After applying veganFriendly = 1, maxPrice = 50, and maxDistance = 10, restaurants 3, 1, and 5 remain and are ordered by rating from highest to lowest.
Example 2
Input
restaurants = [[1,4,1,40,10],[2,8,0,50,5],[3,8,1,30,4],[4,10,0,10,3],[5,1,1,15,1]], veganFriendly = 0, maxPrice = 50, maxDistance = 10Output
[4,3,2,1,5]With veganFriendly = 0, all restaurants are considered, then sorted by rating descending and id descending for ties.
Constraints
- 1 <= restaurants.length <= 10^4
- restaurants[i].length == 5
- 1 <= idi, ratingi, pricei, distancei <= 10^5
- 1 <= maxPrice, maxDistance <= 10^5
- veganFriendlyi and veganFriendly are 0 or 1.
- All idi are distinct.