Longest Low-Slippage Execution Window
Problem statement
Each execution log row is [timestamp, venue, fillPrice, benchmarkPrice, volume], with integer numeric fields encoded as strings. Filter to targetVenue, then sort by increasing timestamp; equal timestamps retain input order.
The slippage cost of a row is abs(fillPrice - benchmarkPrice) * volume. Return the maximum length of a contiguous filtered window whose fill-price range is at most maxPriceRange and whose total slippage cost is at most maxSlippage. Return 0 if no target row is valid.
Function
longestExecutionWindow(logs: String[][], targetVenue: String, maxPriceRange: int, maxSlippage: long) → intExamples
Example 1
logs = [["3","A","103","100","2"],["1","A","100","100","5"],["2","B","90","90","1"],["2","A","101","100","2"]]targetVenue = "A"maxPriceRange = 3maxSlippage = 8return = 3After filtering and sorting, all three A rows have range 3 and total slippage 8.
Example 2
logs = [["1","B","10","10","1"]]targetVenue = "A"maxPriceRange = 0maxSlippage = 0return = 0No row belongs to the target venue.
Constraints
0 <= logs.length <= 500.- Prices, volume, and bounds are nonnegative integers.
- Slippage totals fit in a 64-bit signed integer.