Problem · Array
Maximum Laptop Rating in a Price Range
Learn this problemProblem statement
You are given n laptops. Laptop i has price prices[i] and rating ratings[i].
For each inclusive price query [low, high], return the maximum rating among laptops whose price is between low and high. Return -1 for a query whose price range contains no laptop.
Multiple laptops may have the same price; all of them are eligible for a matching query.
Function
maximumRatings(prices: int[], ratings: int[], queries: int[][]) → int[]Examples
Example 1
prices = [1000,1100,1300,1700,2000]ratings = [300,400,200,500,600]queries = [[1000,1400],[1700,1900],[0,2000]]return = [400,500,600]The highest eligible ratings for the three inclusive ranges are 400, 500, and 600, respectively.
Example 2
prices = [5,1,9]ratings = [40,10,30]queries = [[1,9],[2,8]]return = [40,40]The full range has maximum rating 40. The narrower range includes only the laptop priced at 5, which also has rating 40.
Constraints
1 ≤ prices.length = ratings.length ≤ 10^61 ≤ queries.length ≤ 10^61 ≤ prices[i], ratings[i] ≤ 10^9- Each query contains exactly two values
[low, high]with0 ≤ low ≤ high ≤ 10^9.
More Postman problems
- Group Duplicate Files by ContentONSITE INTERVIEW · Seen Feb 2026
- Encode and Decode a String StreamONSITE INTERVIEW · Seen May 2024
- Configuration SystemOA · Seen Sep 2020
- Large ResponsesOA · Seen Sep 2020
- Minimum Swaps to Sort an ArrayOA · Seen Aug 2020
- Validate IP AddressOA · Seen Aug 2020
- Without WhitespacesOA · Seen Sep 2019