Loading...
Loading...
You are given five arrays of the same length n that describe n records. Record i has a time timestamps[i], a label venues[i], a price fillPrices[i], a reference price benchmarkPrices[i], and a count volumes[i]. You are also given a string targetVenue and two integers maxSpread and maxCost.
Keep only the records whose label equals targetVenue, and put the kept records in increasing order of time. You can assume no two records that share a label also share a time.
The cost of a record is abs(fillPrices[i] - benchmarkPrices[i]) * volumes[i].
A window is a contiguous block of the kept records in that order. A window fits the budgets when both of these hold:
maxSpread;maxCost.Return the number of records in the longest window that fits the budgets. If no record has the label targetVenue, return 0. If no window fits the budgets, return 0.
Input: timestamps = [104,101,102,101,103], venues = ["alpha","beta","alpha","alpha","alpha"], fillPrices = [105,200,101,100,103], benchmarkPrices = [100,200,100,100,100], volumes = [1,10,2,1,1], targetVenue = "alpha", maxSpread = 3, maxCost = 5
Output: 3
Explanation: The four records labeled "alpha", in time order, have prices 100, 101, 103, 105 and costs 0, 2, 3, 5. The first three make a window with spread 103 - 100 = 3 and total cost 0 + 2 + 3 = 5, so both budgets are met. Taking all four raises the spread to 5 and the cost to 10, so 3 is the longest.
Input: timestamps = [5,6], venues = ["beta","gamma"], fillPrices = [10,20], benchmarkPrices = [10,20], volumes = [1,1], targetVenue = "alpha", maxSpread = 100, maxCost = 100
Output: 0
Explanation: No record carries the label "alpha", so no window exists at all.
Input: timestamps = [1,2,3], venues = ["alpha","alpha","alpha"], fillPrices = [7,7,7], benchmarkPrices = [5,5,5], volumes = [1,1,1], targetVenue = "alpha", maxSpread = 0, maxCost = 4
Output: 2
Explanation: Every price is 7, so every window has spread 0. Each record costs abs(7 - 5) * 1 = 2, so two records total 4 and fit the cost budget, while all three total 6 and do not.
timestamps.lengthvenues.length = fillPrices.length = benchmarkPrices.length = volumes.length =ntimestamps[i] ≤109venues[i] and targetVenue are 1 to 10 characters long, each a lowercase letter or a digitfillPrices[i], benchmarkPrices[i] ≤104volumes[i] ≤100maxSpread ≤104maxCost ≤109