Tap here to switch tabs
Problem
Submissions

Problem: Filter Restaurants by Vegan-Friendly, Price, Distance

Try to solve the Filter Restaurants by Vegan-Friendly, Price, Distance problem.

Statement

You are given an array restaurants where restaurants[i] = [id_i, rating_i, veganFriendly_i, price_i, distance_i]. You are also given the filtering criteria veganFriendly, maxPrice, and maxDistance.

Filter the restaurants based on the following conditions:

  • If veganFriendly equals 11, only select restaurants where veganFriendly_i equals 11. If veganFriendly equals 00, select restaurants regardless of their veganFriendly_i value.

  • Only select restaurants where price_i \leq maxPrice.

  • Only select restaurants where distance_i \leq maxDistance.

Return the list of id values of the filtered restaurants, sorted by rating in descending order. If multiple restaurants share the same rating, sort them by id in descending order.

Constraints:

  • 1≤1 \leq restaurants.length ≤104\leq 10^4

  • restaurants[i].length =5= 5

  • 1≤1 \leq id_i, rating_i, price_i, distance_i ≤105\leq 10^5

  • 1≤1 \leq maxPrice, maxDistance ≤105\leq 10^5

  • veganFriendly_i and veganFriendly are either 00 or 11.

  • All id_i are distinct.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Filter Restaurants by Vegan-Friendly, Price, Distance

Try to solve the Filter Restaurants by Vegan-Friendly, Price, Distance problem.

Statement

You are given an array restaurants where restaurants[i] = [id_i, rating_i, veganFriendly_i, price_i, distance_i]. You are also given the filtering criteria veganFriendly, maxPrice, and maxDistance.

Filter the restaurants based on the following conditions:

  • If veganFriendly equals 11, only select restaurants where veganFriendly_i equals 11. If veganFriendly equals 00, select restaurants regardless of their veganFriendly_i value.

  • Only select restaurants where price_i \leq maxPrice.

  • Only select restaurants where distance_i \leq maxDistance.

Return the list of id values of the filtered restaurants, sorted by rating in descending order. If multiple restaurants share the same rating, sort them by id in descending order.

Constraints:

  • 1≤1 \leq restaurants.length ≤104\leq 10^4

  • restaurants[i].length =5= 5

  • 1≤1 \leq id_i, rating_i, price_i, distance_i ≤105\leq 10^5

  • 1≤1 \leq maxPrice, maxDistance ≤105\leq 10^5

  • veganFriendly_i and veganFriendly are either 00 or 11.

  • All id_i are distinct.