You are given two arrays of positive integers containing information about some items on the market: one with their prices, and the second with their ratings from 1 to 5. Here, prices[i] corresponds to the price of the i-th item, and ratings[i] corresponds to the rating of the i-th item.
Find the item with the highest ratio of rating / price and return its index. If this ratio is equal across multiple items, return the item with the lowest index.
Note: You are not expected to provide the most optimal solution, but a solution with time complexity not worse than O(prices.length^3) will fit within the execution time limit.
Examples
01 · Example 1
prices = [7, 5, 2, 11] ratings = [3, 4, 1, 3] return = 1
More Meta problems
- Merge Three Sorted ArraysPHONE SCREEN · Seen May 2026
- Diagonal Traverse (for E4 ;)PHONE SCREEN · Seen Mar 2025
- Find Peak ElementPHONE SCREEN · Seen Mar 2025
- Find Pair Closest to K (for E5 :)PHONE SCREEN · Seen Feb 2025
- Get Minimum Round Trip Cost (: for E4 && E5 :)PHONE SCREEN · Seen Feb 2025
- Max Consecutive Ones III (for E5 :)PHONE SCREEN · Seen Feb 2025
- Nested List Weight Sum (for E4)PHONE SCREEN · Seen Feb 2025
- Sliding Window Average (Meta Canada, E4/E5 :)PHONE SCREEN · Seen Dec 2024
public int solution(int[] prices, int[] ratings) {
// write your code here
}
prices[7, 5, 2, 11]
ratings[3, 4, 1, 3]
expected1
checking account