Write a function to recommend products based on their ratings and prices. The function should take in a list of product information, where each product is an array containing the product's rating and price. The function should also take in a maximum allowed budget and return the product with the highest rating that is within the budget. If there are multiple products with the highest rating within the budget, return the product with the lowest price.
Explanation: Step-by-step: We iterate through the list of products. For each product, we check if its rating is greater than the current max rating and its price is within the budget. If both conditions are met, we update the max rating and add the product to the result list. Finally, we return the result list.
Explanation: Step-by-step: We iterate through the list of products. For each product, we check if its rating is greater than the current max rating and its price is within the budget. If both conditions are met, we update the max rating and add the product to the result list. Finally, we return the result list.
Arrays
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak