Trading Availability
MediumIntervals · Bloomberg
A market data service records when each venue allows trading in each symbol. Each element of windows is [symbol, venue, start, end], meaning symbol is tradable on venue during the half-open interval [start, end): from start inclusive up to but not including end. A window with start == end is empty. The same symbol and venue may have several windows, and they may overlap or touch.
Each element of queries is [symbol, t]. For each query, return how many distinct venues have symbol tradable at time t. A venue counts once even if several of its windows contain t.
Return a list of counts in query order. Symbol and venue names are case-sensitive.
Example 1
- Input:
- windows = [["IBM", "NYSE", 930, 1600], ["IBM", "ARCA", 400, 2000], ["IBM", "NYSE", 1600, 2000], ["MSFT", "NYSE", 930, 1600], ["IBM", "BATS", 1200, 1300]], queries = [["IBM", 1600], ["IBM", 1230], ["IBM", 300], ["MSFT", 1600]]
- Output:
- [2, 3, 0, 0]
- Explanation
- At 1600 IBM's first NYSE window has just closed but its second NYSE window opens, and ARCA is open, so the count is 2. At 1230 NYSE, ARCA and BATS are all open. Nothing is open for IBM at 300, and MSFT's only window ends at 1600, which is excluded.
Example 2
- Input:
- windows = [["AAPL", "IEX", 0, 10], ["AAPL", "IEX", 5, 15]], queries = [["AAPL", 7], ["AAPL", 12]]
- Output:
- [1, 1]
- Explanation
- Both windows belong to IEX. At 7 both contain the time, but IEX is one venue, so the count is 1. At 12 only the second window is open.
Example 3
- Input:
- windows = [["IBM", "N", 0, 10]], queries = [["IBM", 0], ["IBM", 10], ["AAPL", 5]]
- Output:
- [1, 0, 0]
- Explanation
- The window includes its start time 0 but not its end time 10. AAPL has no windows.
Constraints
0 <= windows.length, queries.length <= 10^5-10^9 <= start <= end <= 10^9and-10^9 <= t <= 10^9- Symbols and venues are non-empty strings.