Find Budget-Friendly Popular Pins
Pinterest users discover and save a vast array of pins, including product pins. To enhance the user experience and help them find relevant products efficiently, we often need to filter and organize product listings based on various criteria. This problem focuses on identifying popular product pins that fall within a user's specified budget range and presenting them in an organized manner.
Implement a function findBudgetFriendlyPopularPins that takes a list of Pin objects, a minimum price, a maximum price, and a minimum popularity score. The function should return a new list containing only those Pin objects that satisfy all of the following conditions:
price is greater than or equal to minPrice.price is less than or equal to maxPrice.popularity score is greater than or equal to minPopularity.The returned list of filtered pins must be sorted by their price in ascending order. If two pins have the same price, their relative order in the output list does not matter.
pins: An array of Pin objects. Each Pin object has two properties: price (number) and popularity (number).minPrice: A number representing the minimum acceptable price (inclusive).maxPrice: A number representing the maximum acceptable price (inclusive).minPopularity: A number representing the minimum acceptable popularity score (inclusive).Pin objects, filtered and sorted as described above.pins array is empty, return an empty array.Examples
Example 1
Input:
pins = [{"price": 20, "popularity": 100}, {"price": 50, "popularity": 200}, {"price": 10, "popularity": 50}], minPrice = 15, maxPrice = 60, minPopularity = 80
Output:
[{"price": 20, "popularity": 100}, {"price": 50, "popularity": 200}]
Note:
Pin (price:10, popularity:50) is excluded because its price (10) is less than minPrice (15) and its popularity (50) is less than minPopularity (80). The remaining pins (20,100) and (50,200) match and are sorted by price.
Example 2
Input:
pins = [{"price": 5, "popularity": 10}, {"price": 10, "popularity": 20}], minPrice = 100, maxPrice = 200, minPopularity = 5
Output:
[]
Note:
No pins fall within the specified price range (100-200), so an empty array is returned.
Example 3
Input:
pins = [{"price": 30, "popularity": 50}, {"price": 10, "popularity": 120}, {"price": 20, "popularity": 80}], minPrice = 0, maxPrice = 100, minPopularity = 70
Output:
[{"price": 10, "popularity": 120}, {"price": 20, "popularity": 80}]
Note:
Pin (price:30, popularity:50) is excluded because its popularity (50) is less than minPopularity (70). The remaining pins (10,120) and (20,80) match and are sorted by price.
Constraints
0 <= pins.length <= 10^50 <= pin.price <= 10^90 <= pin.popularity <= 10^90 <= minPrice <= maxPrice <= 10^90 <= minPopularity <= 10^9Loading editor...